Skip to content

Commit

Permalink
[BUGFIX release] Deprecate @each as a leaf node.
Browse files Browse the repository at this point in the history
Update stable version with a deprecation when using `foo.@each` as a
dependent key. This code is removed on beta (2.0.0) and canary (2.1.0)
branches already.
  • Loading branch information
rwjblue committed Aug 8, 2015
1 parent 567de7e commit d623cf9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/ember-htmlbars/tests/helpers/collection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ QUnit.test("empty views should be removed when content is added to the collectio
});

view = EmberView.create({
_viewRegistry: {},
listView: ListView,
listController: listController,
template: compile('{{#collection view.listView content=view.listController tagName="table"}} <td>{{view.content.title}}</td> {{/collection}}')
Expand Down
8 changes: 8 additions & 0 deletions packages/ember-metal/lib/computed.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Ember from 'ember-metal/core';
import { set } from "ember-metal/property_set";
import {
meta,
Expand Down Expand Up @@ -251,6 +252,13 @@ ComputedPropertyPrototype.property = function() {
var args;

var addArg = function(property) {
Ember.deprecate(
`Depending on arrays using a dependent key ending with \`@each\` is deprecated. ` +
`Please refactor from \`Ember.computed('${property}', function() {});\` to \`Ember.computed('${property.slice(0, -6)}.[]', function() {})\`.`,
property.slice(-5) !== '@each',
{ id: 'ember-metal.@each-dependent-key-leaf', until: '2.0.0' }
);

args.push(property);
};

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

var addWatchedProperty = function(path) { paths.push(path); };
var addWatchedProperty = function(path) {
Ember.deprecate(
`Depending on arrays using a dependent key ending with \`@each\` is deprecated. ` +
`Please refactor from \`Ember.observer('${path}', function() {});\` to \`Ember.computed('${path.slice(0, -6)}.[]', function() {})\`.`,
path.slice(-5) !== '@each',
{ id: 'ember-metal.@each-dependent-key-leaf', until: '2.0.0' }
);

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 @@ -59,6 +59,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() {
expectDeprecation(function() {
computed('blazo.@each', function() { });
}, `Depending on arrays using a dependent key ending with \`@each\` is deprecated. Please refactor from \`Ember.computed('blazo.@each', function() {});\` to \`Ember.computed('blazo.[]', function() {})\`.`);

expectDeprecation(function() {
computed('qux', 'zoopa.@each', function() { });
}, `Depending on arrays using a dependent key ending with \`@each\` is deprecated. 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
2 changes: 1 addition & 1 deletion packages/ember-runtime/lib/mixins/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default Mixin.create(MutableEnumerable, {
@property arrangedContent
@private
*/
arrangedContent: computed('content', 'sortProperties.@each', {
arrangedContent: computed('content', 'sortProperties.[]', {
get(key) {
var content = get(this, 'content');
var isSorted = get(this, 'isSorted');
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-views/lib/views/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ var Select = View.extend({
});

return groupedContent;
}).property('optionGroupPath', 'content.@each'),
}).property('optionGroupPath', 'content.[]'),

/**
The view class for option.
Expand All @@ -519,7 +519,7 @@ var Select = View.extend({
}
},

selectionDidChange: observer('selection.@each', function() {
selectionDidChange: observer('selection.[]', function() {
var selection = get(this, 'selection');
if (get(this, 'multiple')) {
if (!isArray(selection)) {
Expand Down
8 changes: 8 additions & 0 deletions packages/ember-views/tests/views/view/child_views_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ QUnit.test('should remove childViews inside {{if}} on destroy', function() {
run(outerView, 'set', 'value', false);

equal(outerView.get('childViews.length'), 0, 'expected no views to be leaked');

run(function() {
outerView.destroy();
});
});

QUnit.test('should remove childViews inside {{each}} on destroy', function() {
Expand Down Expand Up @@ -151,4 +155,8 @@ QUnit.test('should remove childViews inside {{each}} on destroy', function() {
run(outerView, 'set', 'value', false);

equal(outerView.get('childViews.length'), 0, 'expected no views to be leaked');

run(function() {
outerView.destroy();
});
});

0 comments on commit d623cf9

Please sign in to comment.