Skip to content

Commit

Permalink
Merge pull request #19669 from nlfurniss/remove-disable-when
Browse files Browse the repository at this point in the history
Remove deprecated disabledWhen
  • Loading branch information
rwjblue committed Jul 21, 2021
2 parents 24871aa + 92750b9 commit d05402e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 231 deletions.
6 changes: 0 additions & 6 deletions packages/@ember/-internals/glimmer/lib/components/-link-to.ts
Expand Up @@ -879,12 +879,6 @@ const LinkComponent = EmberComponent.extend({
loadingHref: '#',

didReceiveAttrs() {
let { disabledWhen } = this;

if (disabledWhen !== undefined) {
this.set('disabled', disabledWhen);
}

let { params } = this;

if (!params || params.length === 0) {
Expand Down
64 changes: 0 additions & 64 deletions packages/@ember/-internals/glimmer/lib/components/link-to.ts
Expand Up @@ -614,70 +614,6 @@ if (EMBER_MODERNIZED_BUILT_IN_COMPONENTS) {
});
}

// @disabledWhen
{
let superIsSupportedArgument = prototype['isSupportedArgument'];

Object.defineProperty(prototype, 'isSupportedArgument', {
configurable: true,
enumerable: false,
value: function isSupportedArgument(this: LinkTo, name: string): boolean {
if (this.modernized) {
if (name === 'disabledWhen') {
deprecate(
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. ' +
'Use the `@disabled` argument instead.',
false,
{
id: 'ember.link-to.disabled-when',
for: 'ember-source',
since: {},
until: '4.0.0',
}
);

return true;
}
}

return superIsSupportedArgument.call(this, name);
},
});

let superDescriptor = descriptorFor(prototype, 'isDisabled');

assert(
`[BUG] expecting isDisabled to be a getter on <LinkTo>`,
superDescriptor && typeof superDescriptor.get === 'function'
);

let superGetter = superDescriptor.get as (this: LinkTo) => boolean;

Object.defineProperty(prototype, 'isDisabled', {
configurable: true,
enumerable: false,
get: function isDisabled(this: LinkTo): boolean {
if ('disabledWhen' in this.args.named) {
deprecate(
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. ' +
'Use the `@disabled` argument instead.',
false,
{
id: 'ember.link-to.disabled-when',
for: 'ember-source',
since: {},
until: '4.0.0',
}
);

return Boolean(this.named('disabledWhen'));
}

return superGetter.call(this);
},
});
}

// QP
{
let superModelsDescriptor = descriptorFor(prototype, 'models');
Expand Down
Expand Up @@ -147,64 +147,6 @@ moduleFor(
assert.strictEqual(this.$('#about-link').attr('href'), null, 'there is no href attribute');
}

async [`@test [DEPRECATED] it applies a 'disabled' class when disabledWhen`](assert) {
this.addTemplate(
'index',
`
<LinkTo id="about-link-static" @route="about" @disabledWhen="truthy">About</LinkTo>
<LinkTo id="about-link-dynamic" @route="about" @disabledWhen={{this.dynamicDisabledWhen}}>About</LinkTo>
`
);

let controller;

this.add(
'controller:index',
class extends Controller {
constructor(...args) {
super(...args);
controller = this;
}

dynamicDisabledWhen = true;
}
);

await expectDeprecationAsync(
() => this.visit('/'),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

assert.equal(
this.$('#about-link-static.disabled').length,
1,
'The static link is disabled when its disabledWhen is true'
);
assert.equal(
this.$('#about-link-dynamic.disabled').length,
1,
'The dynamic link is disabled when its disabledWhen is true'
);

expectDeprecation(
() => runTask(() => controller.set('dynamicDisabledWhen', false)),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

assert.equal(
this.$('#about-link-static.disabled').length,
1,
'The static link is disabled when its disabledWhen is true'
);
assert.strictEqual(
this.$('#about-link-dynamic.disabled').length,
0,
'The dynamic link is re-enabled when its disabledWhen becomes false'
);
}

async [`@test it applies a 'disabled' class when disabled`](assert) {
this.addTemplate(
'index',
Expand Down Expand Up @@ -384,27 +326,6 @@ moduleFor(
);
}

async [`@test [DEPRECATED] it does not respond to clicks when disabledWhen`](assert) {
this.addTemplate(
'index',
`<LinkTo id="about-link" @route="about" @disabledWhen={{true}}>About</LinkTo>`
);

await expectDeprecationAsync(
() => this.visit('/'),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

await expectDeprecationAsync(
() => this.click('#about-link'),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

assert.strictEqual(this.$('h3.about').length, 0, 'Transitioning did not occur');
}

async [`@test it does not respond to clicks when disabled`](assert) {
this.addTemplate(
'index',
Expand Down Expand Up @@ -451,7 +372,7 @@ moduleFor(
assert.equal(
this.$('h3.about').length,
1,
'Transitioning did occur when disabledWhen became false'
'Transitioning did occur when disabled became false'
);
}

Expand Down
Expand Up @@ -152,64 +152,6 @@ moduleFor(
);
}

async [`@test [DEPRECATED] it applies a 'disabled' class when disabledWhen`](assert) {
this.addTemplate(
'index',
`
<div id="about-link-static">{{#link-to route="about" disabledWhen="truthy"}}About{{/link-to}}</div>
<div id="about-link-dynamic">{{#link-to route="about" disabledWhen=this.dynamicDisabledWhen}}About{{/link-to}}</div>
`
);

let controller;

this.add(
'controller:index',
class extends Controller {
constructor(...args) {
super(...args);
controller = this;
}

dynamicDisabledWhen = true;
}
);

await expectDeprecationAsync(
() => this.visit('/'),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

assert.equal(
this.$('#about-link-static > a.disabled').length,
1,
'The static link is disabled when its disabledWhen is true'
);
assert.equal(
this.$('#about-link-dynamic > a.disabled').length,
1,
'The dynamic link is disabled when its disabledWhen is true'
);

expectDeprecation(
() => runTask(() => controller.set('dynamicDisabledWhen', false)),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

assert.equal(
this.$('#about-link-static > a.disabled').length,
1,
'The static link is disabled when its disabledWhen is true'
);
assert.strictEqual(
this.$('#about-link-dynamic > a.disabled').length,
0,
'The dynamic link is re-enabled when its disabledWhen becomes false'
);
}

async [`@test it applies a 'disabled' class when disabled`](assert) {
this.addTemplate(
'index',
Expand Down Expand Up @@ -251,7 +193,7 @@ moduleFor(
assert.equal(
this.$('#about-link-static > a.disabled').length,
1,
'The static link is disabled when its disabledWhen is true'
'The static link is disabled when its disabled is true'
);
assert.strictEqual(
this.$('#about-link-dynamic > a.disabled').length,
Expand Down Expand Up @@ -396,27 +338,6 @@ moduleFor(
);
}

async [`@test [DEPRECATED] it does not respond to clicks when disabledWhen`](assert) {
this.addTemplate(
'index',
`<div id="about-link">{{#link-to route="about" disabledWhen=true}}About{{/link-to}}</div>`
);

await expectDeprecationAsync(
() => this.visit('/'),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

await expectDeprecationAsync(
() => this.click('#about-link > a'),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

assert.strictEqual(this.$('h3.about').length, 0, 'Transitioning did not occur');
}

async [`@test it does not respond to clicks when disabled`](assert) {
this.addTemplate(
'index',
Expand Down Expand Up @@ -463,7 +384,7 @@ moduleFor(
assert.equal(
this.$('h3.about').length,
1,
'Transitioning did occur when disabledWhen became false'
'Transitioning did occur when disabled became false'
);
}

Expand Down

0 comments on commit d05402e

Please sign in to comment.