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

Remove attrs because they were deprecated for removal in 4.0 #20671

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 1 addition & 33 deletions packages/@ember/-internals/glimmer/lib/utils/process-args.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { MUTABLE_CELL } from '@ember/-internals/views';
import type { CapturedNamedArguments } from '@glimmer/interfaces';
import type { Reference } from '@glimmer/reference';
import { isUpdatableRef, updateRef, valueForRef } from '@glimmer/reference';
import { valueForRef } from '@glimmer/reference';
import { assert } from '@ember/debug';
import { ARGS } from '../component-managers/curly';
import { ACTIONS } from '../helpers/action';

// ComponentArgs takes EvaluatedNamedArgs and converts them into the
// inputs needed by CurlyComponents (attrs and props, with mutable
// cells, etc).
export function processComponentArgs(namedArgs: CapturedNamedArguments) {
let attrs = Object.create(null);
let props = Object.create(null);

props[ARGS] = namedArgs;
Expand All @@ -20,36 +16,8 @@ export function processComponentArgs(namedArgs: CapturedNamedArguments) {
assert('expected ref', ref);
let value = valueForRef(ref);

let isAction = typeof value === 'function' && ACTIONS.has(value);

if (isUpdatableRef(ref) && !isAction) {
attrs[name] = new MutableCell(ref, value);
} else {
attrs[name] = value;
}

props[name] = value;
}

props.attrs = attrs;

return props;
}

const REF = Symbol('REF');

class MutableCell {
public value: any;
[MUTABLE_CELL]: boolean;
[REF]: Reference<unknown>;

constructor(ref: Reference<unknown>, value: any) {
this[MUTABLE_CELL] = true;
this[REF] = ref;
this.value = value;
}

update(val: any) {
updateRef(this[REF], val);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1259,38 +1259,6 @@
this.assertText('somecomponent');
}

['@test non-block with properties access via attrs is asserted against']() {
expectAssertion(() => {
this.registerComponent('non-block', {
template: 'In layout - someProp: {{attrs.someProp}}',
});
}, "Using {{attrs}} to reference named arguments is not supported. {{attrs.someProp}} should be updated to {{@someProp}}. ('my-app/templates/components/non-block.hbs' @ L1:C24) ");
}

['@test non-block with properties on this.attrs']() {
this.registerComponent('non-block', {
template: 'In layout - someProp: {{this.attrs.someProp}}',
});

this.render('{{non-block someProp=this.prop}}', {
prop: 'something here',
});

this.assertText('In layout - someProp: something here');

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

this.assertText('In layout - someProp: something here');

runTask(() => this.context.set('prop', 'other thing there'));

this.assertText('In layout - someProp: other thing there');

runTask(() => this.context.set('prop', 'something here'));

this.assertText('In layout - someProp: something here');
}

['@test non-block with named argument']() {
this.registerComponent('non-block', {
template: 'In layout - someProp: {{@someProp}}',
Expand Down Expand Up @@ -1476,13 +1444,10 @@
);
}

['@test this.attrs.foo === @foo === foo']() {
['@test @foo === foo']() {
this.registerComponent('foo-bar', {
template: strip`
Args: {{this.attrs.value}} | {{@value}} | {{this.value}}
{{#each this.attrs.items as |item|}}
{{item}}
{{/each}}
Args: {{@value}} | {{this.value}}
{{#each @items as |item|}}
{{item}}
{{/each}}
Expand All @@ -1506,11 +1471,11 @@
this.context.set('model.items', [1]);
});

this.assertText(strip`Args: lul | lul | lul111`);
this.assertText(strip`Args: lul | lul11`);

runTask(() => this.context.set('model', { value: 'wat', items: [1, 2, 3] }));

this.assertText('Args: wat | wat | wat123123123');
this.assertText('Args: wat | wat123123');
}

['@test non-block with properties on self']() {
Expand Down Expand Up @@ -1567,44 +1532,6 @@
this.assertText('In layout - someProp: something here - In template');
}

['@test block with properties on attrs is asserted against']() {
expectAssertion(() => {
this.registerComponent('with-block', {
template: 'In layout - someProp: {{attrs.someProp}} - {{yield}}',
});
}, "Using {{attrs}} to reference named arguments is not supported. {{attrs.someProp}} should be updated to {{@someProp}}. ('my-app/templates/components/with-block.hbs' @ L1:C24) ");
}

['@test block with properties on this.attrs']() {
this.registerComponent('with-block', {
template: 'In layout - someProp: {{this.attrs.someProp}} - {{yield}}',
});

this.render(
strip`
{{#with-block someProp=this.prop}}
In template
{{/with-block}}`,
{
prop: 'something here',
}
);

this.assertText('In layout - someProp: something here - In template');

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

this.assertText('In layout - someProp: something here - In template');

runTask(() => this.context.set('prop', 'something else'));

this.assertText('In layout - someProp: something else - In template');

runTask(() => this.context.set('prop', 'something here'));

this.assertText('In layout - someProp: something here - In template');
}

['@test block with named argument']() {
this.registerComponent('with-block', {
template: 'In layout - someProp: {{@someProp}} - {{yield}}',
Expand Down Expand Up @@ -3088,9 +3015,9 @@
this.didInit = true;
},

didReceiveAttrs() {
didReceiveAttrs(...args) {

Check failure on line 3018 in packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js

View workflow job for this annotation

GitHub Actions / Linting

'args' is defined but never used
assert.ok(this.didInit, 'expected init to have run before didReceiveAttrs');
this.set('barCopy', this.attrs.bar.value + 1);
this.set('barCopy', this.bar + 1);
},

barCopyDidChange: observer('barCopy', () => {
Expand Down Expand Up @@ -3290,36 +3217,6 @@
this.assertText('hello');
}

['@test using attrs for positional params is asserted against']() {
let MyComponent = Component.extend();

expectAssertion(() => {
this.registerComponent('foo-bar', {
ComponentClass: MyComponent.reopenClass({
positionalParams: ['myVar'],
}),
template:
'MyVar1: {{attrs.myVar}} {{this.myVar}} MyVar2: {{this.myVar2}} {{attrs.myVar2}}',
});
}, "Using {{attrs}} to reference named arguments is not supported. {{attrs.myVar}} should be updated to {{@myVar}}. ('my-app/templates/components/foo-bar.hbs' @ L1:C10) ");
}

['@test using this.attrs for positional params']() {
let MyComponent = Component.extend();

this.registerComponent('foo-bar', {
ComponentClass: MyComponent.reopenClass({
positionalParams: ['myVar'],
}),
template:
'MyVar1: {{this.attrs.myVar}} {{this.myVar}} MyVar2: {{this.myVar2}} {{this.attrs.myVar2}}',
});

this.render('{{foo-bar 1 myVar2=2}}');

this.assertText('MyVar1: 1 1 MyVar2: 2 2');
}

['@test using named arguments for positional params']() {
let MyComponent = Component.extend();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ moduleFor(
component = this;
},
fireAction() {
this.attrs.submit();
this.submit();
},
});

Expand Down Expand Up @@ -101,7 +101,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
returnedValue = this.attrs.submit();
returnedValue = this.submit();
},
});

Expand Down Expand Up @@ -141,7 +141,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
this.attrs.submit();
this.submit();
},
});

Expand Down Expand Up @@ -191,7 +191,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
this.attrs.submit(fourth);
this.submit(fourth);
},
});

Expand Down Expand Up @@ -236,7 +236,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
this.attrs.submit();
this.submit();
},
});

Expand Down Expand Up @@ -283,7 +283,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
this.attrs.submit();
this.submit();
},
});

Expand Down Expand Up @@ -345,7 +345,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
this.attrs.submit(second, third);
this.submit(second, third);
},
});

Expand Down Expand Up @@ -399,7 +399,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
this.attrs.submit(newValue);
this.submit(newValue);
},
});

Expand Down Expand Up @@ -442,7 +442,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
this.attrs.submit();
this.submit();
},
});

Expand Down Expand Up @@ -490,7 +490,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
actualReturnedValue = this.attrs.submit(second);
actualReturnedValue = this.submit(second);
},
});

Expand Down Expand Up @@ -583,7 +583,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
this.attrs.submit();
this.submit();
},
});

Expand Down Expand Up @@ -630,7 +630,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
this.attrs.submit({
this.submit({
readProp: newValue,
});
},
Expand Down Expand Up @@ -678,7 +678,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
this.attrs.submit({
this.submit({
readProp: newValue,
});
},
Expand Down Expand Up @@ -721,7 +721,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
this.attrs.submit();
this.submit();
},
});

Expand Down Expand Up @@ -772,7 +772,7 @@ moduleFor(
this.get('submit')(second);
this.get('attrs-submit')(second);
let attrsSubmitReturnValue = this.attrs['attrs-submit'](second);
let submitReturnValue = this.attrs.submit(second);
let submitReturnValue = this.submit(second);

assert.equal(
attrsSubmitReturnValue,
Expand Down Expand Up @@ -832,7 +832,7 @@ moduleFor(
innerComponent = this;
},
fireAction() {
this.attrs.submit();
this.submit();
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,26 +184,6 @@ moduleFor(

this.assertText('Hello world');
}

['@test `attrs` can be used as a block param [GH#14678]']() {
this.render('{{#let this.hash as |attrs|}}[{{this.hash.foo}}-{{attrs.foo}}]{{/let}}', {
hash: { foo: 'foo' },
});

this.assertText('[foo-foo]');

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

this.assertText('[foo-foo]');

runTask(() => this.context.set('hash.foo', 'FOO'));

this.assertText('[FOO-FOO]');

runTask(() => this.context.set('hash.foo', 'foo'));

this.assertText('[foo-foo]');
}
}
);

Expand Down