Skip to content

Commit

Permalink
Merge pull request #11774 from machty/stable-enumerable-deprecations
Browse files Browse the repository at this point in the history
[BUGFIX release] add warnings to deprecated Enumerable methods
  • Loading branch information
machty committed Jul 16, 2015
2 parents c4149d9 + 909441d commit cc99723
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 21 deletions.
26 changes: 16 additions & 10 deletions packages/ember-runtime/lib/mixins/enumerable.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ function iter(key, value) {
return i;
}

function deprecatingAliasMethod(oldName, newName) {
return function() {
Ember.deprecate(`Ember.Enumerable.${oldName} is deprecated. Use ${newName} instead.`);
return this[newName](...arguments);
};
}

/**
This mixin defines the common interface implemented by enumerable objects
in Ember. Most of these methods follow the standard Array iteration
Expand Down Expand Up @@ -369,8 +376,7 @@ export default Mixin.create({
@deprecated Use `mapBy` instead
@private
*/

mapProperty: aliasMethod('mapBy'),
mapProperty: deprecatingAliasMethod('mapProperty', 'mapBy'),

/**
Returns an array with all of the items in the enumeration that the passed
Expand Down Expand Up @@ -473,7 +479,7 @@ export default Mixin.create({
@deprecated Use `filterBy` instead
@private
*/
filterProperty: aliasMethod('filterBy'),
filterProperty: deprecatingAliasMethod('filterProperty', 'filterBy'),

/**
Returns an array with the items that do not have truthy values for
Expand Down Expand Up @@ -512,7 +518,7 @@ export default Mixin.create({
@deprecated Use `rejectBy` instead
@private
*/
rejectProperty: aliasMethod('rejectBy'),
rejectProperty: deprecatingAliasMethod('rejectProperty', 'rejectBy'),

/**
Returns the first item in the array for which the callback returns true.
Expand Down Expand Up @@ -602,7 +608,7 @@ export default Mixin.create({
@deprecated Use `findBy` instead
@private
*/
findProperty: aliasMethod('findBy'),
findProperty: deprecatingAliasMethod('findProperty', 'findBy'),

/**
Returns `true` if the passed function returns true for every item in the
Expand Down Expand Up @@ -653,7 +659,7 @@ export default Mixin.create({
@return {Boolean}
@public
*/
everyBy: aliasMethod('isEvery'),
everyBy: deprecatingAliasMethod('everyBy', 'isEvery'),

/**
@method everyProperty
Expand All @@ -663,7 +669,7 @@ export default Mixin.create({
@return {Boolean}
@private
*/
everyProperty: aliasMethod('isEvery'),
everyProperty: deprecatingAliasMethod('everyProperty', 'isEvery'),

/**
Returns `true` if the passed property resolves to the value of the second
Expand Down Expand Up @@ -776,7 +782,7 @@ export default Mixin.create({
@deprecated Use `any` instead
@private
*/
some: aliasMethod('any'),
some: deprecatingAliasMethod('some', 'any'),

/**
Returns `true` if the passed property resolves to the value of the second
Expand All @@ -802,7 +808,7 @@ export default Mixin.create({
@deprecated Use `isAny` instead
@private
*/
anyBy: aliasMethod('isAny'),
anyBy: deprecatingAliasMethod('anyBy', 'isAny'),

/**
@method someProperty
Expand All @@ -812,7 +818,7 @@ export default Mixin.create({
@deprecated Use `isAny` instead
@private
*/
someProperty: aliasMethod('isAny'),
someProperty: deprecatingAliasMethod('someProperty', 'isAny'),

/**
This will combine the values of the enumerator into a single value. It
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1521,9 +1521,9 @@ QUnit.test("it can filter and sort when both depend on the same item property",
todos = get(obj, 'todos');
});

deepEqual(todos.mapProperty('name'), ['E', 'D', 'C', 'B', 'A'], "precond - todos initially correct");
deepEqual(sorted.mapProperty('name'), ['A', 'B', 'C', 'D', 'E'], "precond - sorted initially correct");
deepEqual(filtered.mapProperty('name'), ['A', 'C', 'E'], "precond - filtered initially correct");
deepEqual(todos.mapBy('name'), ['E', 'D', 'C', 'B', 'A'], "precond - todos initially correct");
deepEqual(sorted.mapBy('name'), ['A', 'B', 'C', 'D', 'E'], "precond - sorted initially correct");
deepEqual(filtered.mapBy('name'), ['A', 'C', 'E'], "precond - filtered initially correct");

run(function() {
beginPropertyChanges();
Expand All @@ -1539,9 +1539,9 @@ QUnit.test("it can filter and sort when both depend on the same item property",
endPropertyChanges();
});

deepEqual(todos.mapProperty('name'), ['E', 'D', 'C', 'B', 'A'], "precond - todos remain correct");
deepEqual(sorted.mapProperty('name'), ['A', 'B', 'C', 'E', 'D'], "precond - sorted updated correctly");
deepEqual(filtered.mapProperty('name'), ['A', 'C', 'E', 'D'], "filtered updated correctly");
deepEqual(todos.mapBy('name'), ['E', 'D', 'C', 'B', 'A'], "precond - todos remain correct");
deepEqual(sorted.mapBy('name'), ['A', 'B', 'C', 'E', 'D'], "precond - sorted updated correctly");
deepEqual(filtered.mapBy('name'), ['A', 'C', 'E', 'D'], "filtered updated correctly");
});

QUnit.module('Chaining array and reduced CPs', {
Expand Down
3 changes: 2 additions & 1 deletion packages/ember-runtime/tests/suites/enumerable/any.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ suite.test('any should produce correct results even if the matching element is u
equal(result, true, 'return value of obj.any');
});


/*
suite.test('any should be aliased to some', function() {
var obj = this.newObject();
var ary = this.toArray(obj);
Expand Down Expand Up @@ -102,5 +102,6 @@ suite.test('any should be aliased to some', function() {
equal(someResult, anyResult);
});
*/

export default suite;
2 changes: 2 additions & 0 deletions packages/ember-runtime/tests/suites/enumerable/every.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ suite.test('should return true if every property matches null', function() {
equal(obj.isEvery('bar', null), false, "isEvery('bar', null)");
});

/*
suite.test('everyBy should be aliased to isEvery', function() {
var obj = this.newObject();
equal(obj.isEvery, obj.everyBy);
Expand All @@ -86,6 +87,7 @@ suite.test('everyProperty should be aliased to isEvery', function() {
var obj = this.newObject();
equal(obj.isEvery, obj.everyProperty);
});
*/

suite.test('should return true if every property is undefined', function() {
var obj = this.newObject([
Expand Down
2 changes: 2 additions & 0 deletions packages/ember-runtime/tests/suites/enumerable/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ suite.test('should not match undefined properties without second argument', func
deepEqual(obj.filterBy('foo'), ary.slice(0, 2), "filterBy('foo', 3)')");
});

/*
suite.test('should be aliased to filterProperty', function() {
var ary = [];
equal(ary.filterProperty, ary.filterBy);
});
*/

export default suite;
2 changes: 2 additions & 0 deletions packages/ember-runtime/tests/suites/enumerable/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ suite.test('should return first undefined property match', function() {
equal(obj.findBy('bar', undefined), ary[1], "findBy('bar', undefined)");
});

/*
suite.test('should be aliased to findProperty', function() {
var obj;
obj = this.newObject([]);
equal(obj.findProperty, obj.findBy);
});
*/

export default suite;
2 changes: 2 additions & 0 deletions packages/ember-runtime/tests/suites/enumerable/is_any.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ suite.test('should not match undefined properties without second argument', func
equal(obj.isAny('foo'), false, "isAny('foo', undefined)");
});

/*
suite.test('anyBy should be aliased to isAny', function() {
var obj = this.newObject();
equal(obj.isAny, obj.anyBy);
Expand All @@ -70,5 +71,6 @@ suite.test('isAny should be aliased to someProperty', function() {
var obj = this.newObject();
equal(obj.someProperty, obj.isAny);
});
*/

export default suite;
2 changes: 2 additions & 0 deletions packages/ember-runtime/tests/suites/enumerable/mapBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ suite.test('should work also through getEach alias', function() {
equal(obj.getEach('a').join(''), '12');
});

/*
suite.test('should be aliased to mapProperty', function() {
var obj = this.newObject([]);
equal(obj.mapProperty, obj.mapBy);
});
*/

export default suite;
2 changes: 2 additions & 0 deletions packages/ember-runtime/tests/suites/enumerable/reject.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ suite.test('should match undefined, null, or false properties without second arg
deepEqual(obj.rejectBy('foo'), ary.slice(2), "rejectBy('foo')')");
});

/*
suite.test('should be aliased to rejectProperty', function() {
var ary =[];
equal(ary.rejectProperty, ary.rejectBy);
});
*/

export default suite;
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ QUnit.module('Model Dep Query Params', {
deepEqual(params, self.expectedModelHookParams, 'the ArticleRoute model hook received the expected merged dynamic segment + query params hash');
self.expectedModelHookParams = null;
}
return articles.findProperty('id', params.id);
return articles.findBy('id', params.id);
}
});

Expand Down Expand Up @@ -421,7 +421,7 @@ QUnit.module('Model Dep Query Params (nested)', {
deepEqual(params, self.expectedModelHookParams, 'the ArticleRoute model hook received the expected merged dynamic segment + query params hash');
self.expectedModelHookParams = null;
}
return site_articles.findProperty('id', params.id);
return site_articles.findBy('id', params.id);
}
});

Expand Down Expand Up @@ -511,7 +511,7 @@ QUnit.module('Model Dep Query Params (nested & more than 1 dynamic segment)', {
deepEqual(params, self.expectedSiteModelHookParams, 'the SiteRoute model hook received the expected merged dynamic segment + query params hash');
self.expectedSiteModelHookParams = null;
}
return sites.findProperty('id', params.site_id);
return sites.findBy('id', params.site_id);
}
});
App.SiteArticleRoute = Ember.Route.extend({
Expand All @@ -520,7 +520,7 @@ QUnit.module('Model Dep Query Params (nested & more than 1 dynamic segment)', {
deepEqual(params, self.expectedArticleModelHookParams, 'the SiteArticleRoute model hook received the expected merged dynamic segment + query params hash');
self.expectedArticleModelHookParams = null;
}
return site_articles.findProperty('id', params.article_id);
return site_articles.findBy('id', params.article_id);
}
});

Expand Down

0 comments on commit cc99723

Please sign in to comment.