Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecation for this.$() in curly components #17488

Merged
merged 1 commit into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3612,6 +3612,8 @@ if (jQueryDisabled) {
class extends RenderingTestCase {
['@test it has a jQuery proxy to the element']() {
let instance;
let element1;
let element2;

let FooBarComponent = Component.extend({
init() {
Expand All @@ -3627,13 +3629,17 @@ if (jQueryDisabled) {

this.render('{{foo-bar}}');

let element1 = instance.$()[0];
expectDeprecation(() => {
element1 = instance.$()[0];
}, 'Using this.$() in a component has been deprecated, consider using this.element');

this.assertComponentElement(element1, { content: 'hello' });

runTask(() => this.rerender());

let element2 = instance.$()[0];
expectDeprecation(() => {
element2 = instance.$()[0];
}, 'Using this.$() in a component has been deprecated, consider using this.element');

this.assertComponentElement(element2, { content: 'hello' });

Expand All @@ -3642,6 +3648,7 @@ if (jQueryDisabled) {

['@test it scopes the jQuery proxy to the component element'](assert) {
let instance;
let $span;

let FooBarComponent = Component.extend({
init() {
Expand All @@ -3657,14 +3664,18 @@ if (jQueryDisabled) {

this.render('<span class="outer">outer</span>{{foo-bar}}');

let $span = instance.$('span');
expectDeprecation(() => {
$span = instance.$('span');
}, 'Using this.$() in a component has been deprecated, consider using this.element');

assert.equal($span.length, 1);
assert.equal($span.attr('class'), 'inner');

runTask(() => this.rerender());

$span = instance.$('span');
expectDeprecation(() => {
$span = instance.$('span');
}, 'Using this.$() in a component has been deprecated, consider using this.element');

assert.equal($span.length, 1);
assert.equal($span.attr('class'), 'inner');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,8 @@ if (jQueryDisabled) {
class extends RenderingTestCase {
['@test it has a jQuery proxy to the element']() {
let instance;
let element1;
let element2;

let FooBarComponent = Component.extend({
init() {
Expand All @@ -850,13 +852,17 @@ if (jQueryDisabled) {

this.render('{{component "foo-bar"}}');

let element1 = instance.$()[0];
expectDeprecation(() => {
element1 = instance.$()[0];
}, 'Using this.$() in a component has been deprecated, consider using this.element');

this.assertComponentElement(element1, { content: 'hello' });

runTask(() => this.rerender());

let element2 = instance.$()[0];
expectDeprecation(() => {
element2 = instance.$()[0];
}, 'Using this.$() in a component has been deprecated, consider using this.element');

this.assertComponentElement(element2, { content: 'hello' });

Expand All @@ -865,6 +871,7 @@ if (jQueryDisabled) {

['@test it scopes the jQuery proxy to the component element'](assert) {
let instance;
let $span;

let FooBarComponent = Component.extend({
init() {
Expand All @@ -880,14 +887,18 @@ if (jQueryDisabled) {

this.render('<span class="outer">outer</span>{{component "foo-bar"}}');

let $span = instance.$('span');
expectDeprecation(() => {
$span = instance.$('span');
}, 'Using this.$() in a component has been deprecated, consider using this.element');

assert.equal($span.length, 1);
assert.equal($span.attr('class'), 'inner');

runTask(() => this.rerender());

$span = instance.$('span');
expectDeprecation(() => {
$span = instance.$('span');
}, 'Using this.$() in a component has been deprecated, consider using this.element');

assert.equal($span.length, 1);
assert.equal($span.attr('class'), 'inner');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ if (!jQueryDisabled) {
'Run loop and lifecycle hooks - jQuery only',
class extends RenderingTestCase {
['@test lifecycle hooks have proper access to this.$()'](assert) {
assert.expect(6);
assert.expect(7);
let component;
let FooBarComponent = Component.extend({
tagName: 'div',
Expand Down Expand Up @@ -1634,8 +1634,12 @@ if (!jQueryDisabled) {
template: 'hello',
});
let { owner } = this;
let comp = owner.lookup('component:foo-bar');
runAppend(comp);

expectDeprecation(() => {
let comp = owner.lookup('component:foo-bar');
runAppend(comp);
runTask(() => tryInvoke(component, 'destroy'));
}, 'Using this.$() in a component has been deprecated, consider using this.element');
runTask(() => tryInvoke(component, 'destroy'));
}
}
Expand Down
10 changes: 10 additions & 0 deletions packages/@ember/-internals/views/lib/mixins/view_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { assert } from '@ember/debug';
import { hasDOM } from '@ember/-internals/browser-environment';
import { matches } from '../system/utils';
import { default as jQuery, jQueryDisabled } from '../system/jquery';
import { deprecate } from '@ember/debug';

function K() {
return this;
Expand Down Expand Up @@ -177,6 +178,15 @@ export default Mixin.create({
this.tagName !== ''
);
assert('You cannot access this.$() with `jQuery` disabled.', !jQueryDisabled);
deprecate(
'Using this.$() in a component has been deprecated, consider using this.element',
false,
{
id: 'ember-views.curly-components.jquery-element',
until: '4.0.0',
url: 'https://emberjs.com/deprecations/v3.x#toc_jquery-apis',
}
);
if (this.element) {
return sel ? jQuery(sel, this.element) : jQuery(this.element);
}
Expand Down