Skip to content

Commit 0a36691

Browse files
committed
Merge pull request #12847 from jgwhite/deep-each-warning
[BUGFIX beta] Add warning for “deep @each” usage in dependent keys
2 parents 48562e6 + 4cd4615 commit 0a36691

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

.jshintrc

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"expectAssertion",
2222
"expectDeprecation",
2323
"expectNoDeprecation",
24+
"expectWarning",
25+
"expectNoWarning",
2426
"ignoreAssertion",
2527
"ignoreDeprecation",
2628

packages/ember-metal/lib/computed.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assert } from 'ember-metal/debug';
1+
import { assert, warn } from 'ember-metal/debug';
22
import { set } from 'ember-metal/property_set';
33
import { inspect } from 'ember-metal/utils';
44
import { meta as metaFor, peekMeta } from 'ember-metal/meta';
@@ -25,6 +25,8 @@ import {
2525

2626
function UNDEFINED() { }
2727

28+
const DEEP_EACH_REGEX = /\.@each\.[^.]+\./;
29+
2830
// ..........................................................
2931
// COMPUTED PROPERTY
3032
//
@@ -252,6 +254,13 @@ ComputedPropertyPrototype.property = function() {
252254
var args;
253255

254256
var addArg = function(property) {
257+
warn(
258+
`Dependent keys containing @each only work one level deep. ` +
259+
`You cannot use nested forms like [email protected] or [email protected][email protected]. ` +
260+
`Please create an intermediary computed property.`,
261+
DEEP_EACH_REGEX.test(property) === false,
262+
{ id: 'ember-metal.computed-deep-each' }
263+
);
255264
args.push(property);
256265
};
257266

packages/ember-metal/tests/computed_test.js

+22
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ QUnit.test('defining a computed property with a dependent key ending with @each
8888
deepEqual(cp._dependentKeys, ['qux', 'zoopa.[]']);
8989
});
9090

91+
QUnit.test('defining a computed property with a dependent key more than one level deep beyond @each is not supported', function() {
92+
let warning = `Dependent keys containing @each only work one level deep. ` +
93+
`You cannot use nested forms like [email protected] or [email protected][email protected]. ` +
94+
`Please create an intermediary computed property.`;
95+
96+
expectNoWarning(() => {
97+
computed('todos', () => {});
98+
});
99+
100+
expectNoWarning(() => {
101+
computed('[email protected]', () => {});
102+
});
103+
104+
expectWarning(() => {
105+
computed('[email protected]', () => {});
106+
}, warning);
107+
108+
expectWarning(() => {
109+
computed('[email protected][email protected]', () => {});
110+
}, warning);
111+
});
112+
91113
var objA, objB;
92114
QUnit.module('computed should inherit through prototype', {
93115
setup() {

0 commit comments

Comments
 (0)