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

[BUGFIX beta] Add warning for “deep @each” usage in dependent keys #12847

Merged
merged 1 commit into from
Jan 21, 2016
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
2 changes: 2 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"expectAssertion",
"expectDeprecation",
"expectNoDeprecation",
"expectWarning",
"expectNoWarning",
"ignoreAssertion",
"ignoreDeprecation",

Expand Down
11 changes: 10 additions & 1 deletion packages/ember-metal/lib/computed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from 'ember-metal/debug';
import { assert, warn } from 'ember-metal/debug';
import { set } from 'ember-metal/property_set';
import { inspect } from 'ember-metal/utils';
import { meta as metaFor, peekMeta } from 'ember-metal/meta';
Expand All @@ -25,6 +25,8 @@ import {

function UNDEFINED() { }

const DEEP_EACH_REGEX = /\.@each\.[^.]+\./;

// ..........................................................
// COMPUTED PROPERTY
//
Expand Down Expand Up @@ -252,6 +254,13 @@ ComputedPropertyPrototype.property = function() {
var args;

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

Expand Down
22 changes: 22 additions & 0 deletions packages/ember-metal/tests/computed_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ QUnit.test('defining a computed property with a dependent key ending with @each
deepEqual(cp._dependentKeys, ['qux', 'zoopa.[]']);
});

QUnit.test('defining a computed property with a dependent key more than one level deep beyond @each is not supported', function() {
let warning = `Dependent keys containing @each only work one level deep. ` +
`You cannot use nested forms like [email protected] or [email protected][email protected]. ` +
`Please create an intermediary computed property.`;

expectNoWarning(() => {
computed('todos', () => {});
});

expectNoWarning(() => {
computed('[email protected]', () => {});
});

expectWarning(() => {
computed('[email protected]', () => {});
}, warning);

expectWarning(() => {
computed('[email protected][email protected]', () => {});
}, warning);
});

var objA, objB;
QUnit.module('computed should inherit through prototype', {
setup() {
Expand Down