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 computed deep each #19673

Merged
merged 1 commit into from
Jul 31, 2021
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
29 changes: 1 addition & 28 deletions packages/@ember/-internals/metal/lib/chain-tags.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta, meta as metaFor, peekMeta } from '@ember/-internals/meta';
import { isObject } from '@ember/-internals/utils';
import { assert, deprecate } from '@ember/debug';
import { assert } from '@ember/debug';
import { _WeakSet } from '@glimmer/util';
import {
combine,
Expand Down Expand Up @@ -89,33 +89,6 @@ function getChainTags(
lastSegmentEnd = segmentEnd + 1;
segmentEnd = path.indexOf('.', lastSegmentEnd);

// There should be exactly one segment after an `@each` (i.e. `@each.foo`, not `@each.foo.bar`)
deprecate(
`When using @each in a dependent-key or an observer, ` +
`you can only chain one property level deep after ` +
`the @each. That is, \`${path.slice(0, segmentEnd)}\` ` +
`is allowed but \`${path}\` (which is what you passed) ` +
`is not.\n\n` +
`This was never supported. Currently, the extra segments ` +
`are silently ignored, i.e. \`${path}\` behaves exactly ` +
`the same as \`${path.slice(0, segmentEnd)}\`. ` +
`In the future, this will throw an error.\n\n` +
`If the current behavior is acceptable for your use case, ` +
`please remove the extraneous segments by changing your ` +
`key to \`${path.slice(0, segmentEnd)}\`. ` +
`Otherwise, please create an intermediary computed property ` +
`or switch to using tracked properties.`,
segmentEnd === -1,
{
until: '3.17.0',
id: 'ember-metal.computed-deep-each',
for: 'ember-source',
since: {
enabled: '3.13.0-beta.3',
},
}
);

let arrLength = current.length;

if (
Expand Down
11 changes: 6 additions & 5 deletions packages/@ember/-internals/metal/lib/computed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta, meta as metaFor } from '@ember/-internals/meta';
import { inspect, toString } from '@ember/-internals/utils';
import { assert, warn } from '@ember/debug';
import { assert } from '@ember/debug';
import EmberError from '@ember/error';
import { isDestroyed } from '@glimmer/destroyable';
import { DEBUG } from '@glimmer/env';
Expand Down Expand Up @@ -351,13 +351,14 @@ export class ComputedProperty extends ComputedDescriptor {
let args: string[] = [];

function addArg(property: string): void {
warn(
assert(
`Dependent keys containing @each only work one level deep. ` +
`You used the key "${property}" which is invalid. ` +
`Please create an intermediary computed property.`,
DEEP_EACH_REGEX.test(property) === false,
{ id: 'ember-metal.computed-deep-each' }
`Please create an intermediary computed property or ` +
`switch to using tracked properties.`,
DEEP_EACH_REGEX.test(property) === false
);

args.push(property);
}

Expand Down
38 changes: 6 additions & 32 deletions packages/@ember/-internals/metal/tests/computed_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ moduleFor(
// assert.deepEqual(cp._dependentKeys, ['qux', 'zoopa.[]']);
// }

['@test defining a computed property with a dependent key more than one level deep beyond @each is not supported']() {
['@test defining a computed property with a dependent key more than one level deep beyond @each throws an assertion']() {
expectNoWarning(() => {
obj = {};
defineProperty(
Expand All @@ -185,50 +185,24 @@ moduleFor(
);
});

expectWarning(() => {
let expected = /Dependent keys containing @each only work one level deep./;

expectAssertion(() => {
obj = {};
defineProperty(
obj,
'someProp',
computed('todos.@each.owner.name', () => {})
);
}, /You used the key "todos\.@each\.owner\.name" which is invalid\. /);
}, expected);

expectWarning(() => {
expectAssertion(() => {
obj = {};
defineProperty(
obj,
'someProp',
computed('todos.@each.owner.@each.name', () => {})
);
}, /You used the key "todos\.@each\.owner\.@each\.name" which is invalid\. /);

let expected = new RegExp(
'When using @each in a dependent-key or an observer, ' +
'you can only chain one property level deep after the @each\\. ' +
'That is, `todos\\.@each\\.owner` is allowed but ' +
'`todos\\.@each\\.owner\\.name` \\(which is what you passed\\) is not\\.\n\n' +
'This was never supported\\. Currently, the extra segments ' +
'are silently ignored, i\\.e\\. `todos\\.@each\\.owner\\.name` ' +
'behaves exactly the same as `todos\\.@each\\.owner`\\. ' +
'In the future, this will throw an error\\.\n\n' +
'If the current behavior is acceptable for your use case, ' +
'please remove the extraneous segments by changing your key to ' +
'`todos\\.@each\\.owner`\\. Otherwise, please create an ' +
'intermediary computed property or switch to using tracked properties\\.'
);

expectDeprecation(() => {
obj = {
todos: [],
};
defineProperty(
obj,
'someProp',
computed('todos.@each.owner.name', () => {})
);

get(obj, 'someProp');
}, expected);
}
}
Expand Down