Skip to content

Commit

Permalink
Merge pull request #12848 from emberjs/fix-each-dep
Browse files Browse the repository at this point in the history
Make dependencies that end in `@each` expand to `[]`.
  • Loading branch information
rwjblue committed Jan 20, 2016
2 parents bb163d0 + 0567c11 commit 48562e6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
5 changes: 0 additions & 5 deletions packages/ember-metal/lib/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,6 @@ ComputedPropertyPrototype.property = function() {
var args;

var addArg = function(property) {
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
6 changes: 4 additions & 2 deletions packages/ember-metal/lib/expand_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import EmberError from 'ember-metal/error';

var SPLIT_REGEX = /\{|\}/;

var END_WITH_EACH_REGEX = /\.@each$/;

/**
Expands `pattern`, invoking `callback` for each expansion.
Expand Down Expand Up @@ -50,10 +52,10 @@ export default function expandProperties(pattern, callback) {
});

properties.forEach((property) => {
callback(property.join(''));
callback(property.join('').replace(END_WITH_EACH_REGEX, '.[]'));
});
} else {
callback(pattern);
callback(pattern.replace(END_WITH_EACH_REGEX, '.[]'));
}
}

Expand Down
6 changes: 0 additions & 6 deletions packages/ember-metal/lib/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,12 +750,6 @@ export function observer(...args) {
var paths;

var addWatchedProperty = function(path) {
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);
Expand Down
14 changes: 7 additions & 7 deletions packages/ember-metal/tests/computed_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ 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() {})\`.`);
QUnit.test('defining a computed property with a dependent key ending with @each is expanded to []', function() {
var cp = computed('blazo.@each', 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() {})\`.`);
deepEqual(cp._dependentKeys, ['blazo.[]']);

cp = computed('qux', 'zoopa.@each', function() { });

deepEqual(cp._dependentKeys, ['qux', 'zoopa.[]']);
});

var objA, objB;
Expand Down

0 comments on commit 48562e6

Please sign in to comment.