Skip to content

Commit

Permalink
Merge pull request #12019 from rwjblue/add-assertion-for-at-each
Browse files Browse the repository at this point in the history
[DOC beta] Add helpful assertion when using @each as a leaf in DK.
  • Loading branch information
rwjblue committed Aug 8, 2015
2 parents 4feb881 + 341a876 commit f991405
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/ember-metal/lib/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ ComputedPropertyPrototype.property = function() {
var args;

var addArg = function(property) {
Ember.assert(
`Depending on arrays using a dependent key ending with \`@each\` is no longer supported. ` +
`Please refactor from \`Ember.computed('${property}', function() {});\` to \`Ember.computed('${property.slice(0, -6)}.[]', function() {})\`.`,
property.slice(-5) !== '@each'
);
args.push(property);
};

Expand Down
10 changes: 9 additions & 1 deletion packages/ember-metal/lib/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,15 @@ export function observer(...args) {
var func = args.slice(-1)[0];
var paths;

var addWatchedProperty = function(path) { paths.push(path); };
var addWatchedProperty = function(path) {
Ember.assert(
`Depending on arrays using a dependent key ending with \`@each\` is no longer supported. ` +
`Please refactor from \`Ember.observer('${path}', function() {});\` to \`Ember.observer('${path.slice(0, -6)}.[]', function() {})\`.`,
path.slice(-5) !== '@each'
);

paths.push(path);
};
var _paths = args.slice(0, -1);

if (typeof func !== 'function') {
Expand Down
10 changes: 10 additions & 0 deletions packages/ember-metal/tests/computed_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ QUnit.test('defining computed property should invoke property on set', function(
equal(get(obj, 'foo'), 'computed bar', 'should return new value');
});

QUnit.test('defining a computed property with a dependent key ending with @each is deprecated', function() {
expectAssertion(function() {
computed('blazo.@each', function() { });
}, `Depending on arrays using a dependent key ending with \`@each\` is no longer supported. Please refactor from \`Ember.computed('blazo.@each', function() {});\` to \`Ember.computed('blazo.[]', function() {})\`.`);

expectAssertion(function() {
computed('qux', 'zoopa.@each', function() { });
}, `Depending on arrays using a dependent key ending with \`@each\` is no longer supported. Please refactor from \`Ember.computed('zoopa.@each', function() {});\` to \`Ember.computed('zoopa.[]', function() {})\`.`);
});

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

0 comments on commit f991405

Please sign in to comment.