From 3521d8e86933f6e703bfff324086e9c770a91011 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 26 May 2015 22:51:39 -0400 Subject: [PATCH] [BUGFIX beta] Deprecate Ember.EnumerableUtils. --- .../lib/system/application.js | 4 +- packages/ember-metal/lib/enumerable_utils.js | 38 ++++++++++++++----- .../tests/platform/define_property_test.js | 4 +- packages/ember-runtime/lib/system/subarray.js | 4 +- .../tests/suites/enumerable/map.js | 4 +- .../tests/system/set/extra_test.js | 6 +-- 6 files changed, 39 insertions(+), 21 deletions(-) diff --git a/packages/ember-application/lib/system/application.js b/packages/ember-application/lib/system/application.js index b8f3fde05f2..28bbcc64cb9 100644 --- a/packages/ember-application/lib/system/application.js +++ b/packages/ember-application/lib/system/application.js @@ -16,7 +16,7 @@ import create from "ember-metal/platform/create"; import run from "ember-metal/run_loop"; import { canInvoke } from "ember-metal/utils"; import Controller from "ember-runtime/controllers/controller"; -import EnumerableUtils from "ember-metal/enumerable_utils"; +import { map } from "ember-metal/enumerable_utils"; import ObjectController from "ember-runtime/controllers/object_controller"; import ArrayController from "ember-runtime/controllers/array_controller"; import Renderer from "ember-metal-views/renderer"; @@ -1135,7 +1135,7 @@ function logLibraryVersions() { Ember.LOG_VERSION = false; var libs = Ember.libraries._registry; - var nameLengths = EnumerableUtils.map(libs, function(item) { + var nameLengths = map(libs, function(item) { return get(item, 'name.length'); }); diff --git a/packages/ember-metal/lib/enumerable_utils.js b/packages/ember-metal/lib/enumerable_utils.js index 3a749bafbdf..d4a5be02ed5 100644 --- a/packages/ember-metal/lib/enumerable_utils.js +++ b/packages/ember-metal/lib/enumerable_utils.js @@ -1,3 +1,4 @@ +import Ember from 'ember-metal/core'; // Ember.deprecateFunc import { filter as _filter, forEach as a_forEach, @@ -13,6 +14,7 @@ var splice = Array.prototype.splice; * * @class EnumerableUtils * @namespace Ember + * @deprecated * @static * */ @@ -21,6 +23,7 @@ var splice = Array.prototype.splice; * uses `Ember.ArrayPolyfill`'s-map method when necessary. * * @method map + * @deprecated Use ES5's Array.prototype.map instead. * @param {Object} obj The object that should be mapped * @param {Function} callback The callback to execute * @param {Object} thisArg Value to use as this when executing *callback* @@ -30,12 +33,14 @@ var splice = Array.prototype.splice; export function map(obj, callback, thisArg) { return obj.map ? obj.map(callback, thisArg) : _map.call(obj, callback, thisArg); } +var deprecatedMap = Ember.deprecateFunc('Ember.EnumberableUtils.map is deprecated, please refactor to use Array.prototype.map.', map); /** * Calls the forEach function on the passed object with a specified callback. This * uses `Ember.ArrayPolyfill`'s-forEach method when necessary. * * @method forEach + * @deprecated Use ES5's Array.prototype.forEach instead. * @param {Object} obj The object to call forEach on * @param {Function} callback The callback to execute * @param {Object} thisArg Value to use as this when executing *callback* @@ -44,12 +49,14 @@ export function map(obj, callback, thisArg) { export function forEach(obj, callback, thisArg) { return obj.forEach ? obj.forEach(callback, thisArg) : a_forEach.call(obj, callback, thisArg); } +var deprecatedForEach = Ember.deprecateFunc('Ember.EnumberableUtils.forEach is deprecated, please refactor to use Array.prototype.forEach.', forEach); /** * Calls the filter function on the passed object with a specified callback. This * uses `Ember.ArrayPolyfill`'s-filter method when necessary. * * @method filter + * @deprecated Use ES5's Array.prototype.filter instead. * @param {Object} obj The object to call filter on * @param {Function} callback The callback to execute * @param {Object} thisArg Value to use as this when executing *callback* @@ -60,12 +67,14 @@ export function forEach(obj, callback, thisArg) { export function filter(obj, callback, thisArg) { return obj.filter ? obj.filter(callback, thisArg) : _filter.call(obj, callback, thisArg); } +var deprecatedFilter = Ember.deprecateFunc('Ember.EnumberableUtils.filter is deprecated, please refactor to use Array.prototype.filter.', filter); /** * Calls the indexOf function on the passed object with a specified callback. This * uses `Ember.ArrayPolyfill`'s-indexOf method when necessary. * * @method indexOf + * @deprecated Use ES5's Array.prototype.indexOf instead. * @param {Object} obj The object to call indexOn on * @param {Function} callback The callback to execute * @param {Object} index The index to start searching from @@ -74,6 +83,7 @@ export function filter(obj, callback, thisArg) { export function indexOf(obj, element, index) { return obj.indexOf ? obj.indexOf(element, index) : _indexOf.call(obj, element, index); } +var deprecatedIndexOf = Ember.deprecateFunc('Ember.EnumberableUtils.indexOf is deprecated, please refactor to use Array.prototype.indexOf.', indexOf); /** * Returns an array of indexes of the first occurrences of the passed elements @@ -88,6 +98,7 @@ export function indexOf(obj, element, index) { * ``` * * @method indexesOf + * @deprecated * @param {Object} obj The object to check for element indexes * @param {Array} elements The elements to search for on *obj* * @@ -99,12 +110,14 @@ export function indexesOf(obj, elements) { return indexOf(obj, item); }); } +var deprecatedIndexesOf = Ember.deprecateFunc('Ember.EnumerableUtils.indexesOf is deprecated.', indexesOf); /** * Adds an object to an array. If the array already includes the object this * method has no effect. * * @method addObject + * @deprecated * @param {Array} array The array the passed item should be added to * @param {Object} item The item to add to the passed array * @@ -114,12 +127,14 @@ export function addObject(array, item) { var index = indexOf(array, item); if (index === -1) { array.push(item); } } +var deprecatedAddObject = Ember.deprecateFunc('Ember.EnumerableUtils.addObject is deprecated.', addObject); /** * Removes an object from an array. If the array does not contain the passed * object this method has no effect. * * @method removeObject + * @deprecated * @param {Array} array The array to remove the item from. * @param {Object} item The item to remove from the passed array. * @@ -129,6 +144,7 @@ export function removeObject(array, item) { var index = indexOf(array, item); if (index !== -1) { array.splice(index, 1); } } +var deprecatedRemoveObject = Ember.deprecateFunc('Ember.EnumerableUtils.removeObject is deprecated.', removeObject); export function _replace(array, idx, amt, objects) { var args = [].concat(objects); @@ -169,6 +185,7 @@ export function _replace(array, idx, amt, objects) { * ``` * * @method replace + * @deprecated * @param {Array} array The array the objects should be inserted into. * @param {Number} idx Starting index in the array to replace. If *idx* >= * length, then append to the end of the array. @@ -186,6 +203,7 @@ export function replace(array, idx, amt, objects) { return _replace(array, idx, amt, objects); } } +var deprecatedReplace = Ember.deprecateFunc('Ember.EnumerableUtils.replace is deprecated.', replace); /** * Calculates the intersection of two arrays. This method returns a new array @@ -205,6 +223,7 @@ export function replace(array, idx, amt, objects) { * ``` * * @method intersection + * @deprecated * @param {Array} array1 The first array * @param {Array} array2 The second array * @@ -220,18 +239,19 @@ export function intersection(array1, array2) { return result; } +var deprecatedIntersection = Ember.deprecateFunc('Ember.EnumerableUtils.intersection is deprecated.', intersection); // TODO: this only exists to maintain the existing api, as we move forward it // should only be part of the "global build" via some shim export default { _replace: _replace, - addObject: addObject, - filter: filter, - forEach: forEach, - indexOf: indexOf, - indexesOf: indexesOf, - intersection: intersection, - map: map, - removeObject: removeObject, - replace: replace + addObject: deprecatedAddObject, + filter: deprecatedFilter, + forEach: deprecatedForEach, + indexOf: deprecatedIndexOf, + indexesOf: deprecatedIndexesOf, + intersection: deprecatedIntersection, + map: deprecatedMap, + removeObject: deprecatedRemoveObject, + replace: deprecatedReplace }; diff --git a/packages/ember-metal/tests/platform/define_property_test.js b/packages/ember-metal/tests/platform/define_property_test.js index 3d8cb010124..1b92c439611 100644 --- a/packages/ember-metal/tests/platform/define_property_test.js +++ b/packages/ember-metal/tests/platform/define_property_test.js @@ -3,7 +3,7 @@ import { hasPropertyAccessors, canDefineNonEnumerableProperties } from 'ember-metal/platform/define_property'; -import EnumerableUtils from 'ember-metal/enumerable_utils'; +import { indexOf } from 'ember-metal/enumerable_utils'; function isEnumerable(obj, keyName) { var keys = []; @@ -12,7 +12,7 @@ function isEnumerable(obj, keyName) { keys.push(key); } } - return EnumerableUtils.indexOf(keys, keyName)>=0; + return indexOf(keys, keyName)>=0; } QUnit.module("defineProperty()"); diff --git a/packages/ember-runtime/lib/system/subarray.js b/packages/ember-runtime/lib/system/subarray.js index 4132c03454b..061a8f063e2 100644 --- a/packages/ember-runtime/lib/system/subarray.js +++ b/packages/ember-runtime/lib/system/subarray.js @@ -1,5 +1,5 @@ import EmberError from "ember-metal/error"; -import EnumerableUtils from "ember-metal/enumerable_utils"; +import { forEach } from "ember-metal/enumerable_utils"; var RETAIN = 'r'; var FILTER = 'f'; @@ -168,7 +168,7 @@ SubArray.prototype = { toString() { var str = ""; - EnumerableUtils.forEach(this._operations, function (operation) { + forEach(this._operations, function (operation) { str += " " + operation.type + ":" + operation.count; }); return str.substring(1); diff --git a/packages/ember-runtime/tests/suites/enumerable/map.js b/packages/ember-runtime/tests/suites/enumerable/map.js index 9d6d87efe2a..9aa2cab56ce 100644 --- a/packages/ember-runtime/tests/suites/enumerable/map.js +++ b/packages/ember-runtime/tests/suites/enumerable/map.js @@ -1,5 +1,5 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -import EnumerableUtils from 'ember-metal/enumerable_utils'; +import { map } from 'ember-metal/enumerable_utils'; import {get} from 'ember-metal/property_get'; import {guidFor} from "ember-metal/utils"; @@ -11,7 +11,7 @@ function mapFunc(item) { return item ? item.toString() : null; } suite.test('map should iterate over list', function() { var obj = this.newObject(); - var ary = EnumerableUtils.map(this.toArray(obj), mapFunc); + var ary = map(this.toArray(obj), mapFunc); var found = []; found = obj.map(mapFunc); diff --git a/packages/ember-runtime/tests/system/set/extra_test.js b/packages/ember-runtime/tests/system/set/extra_test.js index 1dc0d5056fb..19ab34ea101 100644 --- a/packages/ember-runtime/tests/system/set/extra_test.js +++ b/packages/ember-runtime/tests/system/set/extra_test.js @@ -1,4 +1,4 @@ -import EnumerableUtils from "ember-metal/enumerable_utils"; +import { indexOf } from "ember-metal/enumerable_utils"; import {get} from "ember-metal/property_get"; import {addObserver} from "ember-metal/observer"; import Set from "ember-runtime/system/set"; @@ -17,7 +17,7 @@ QUnit.test('passing an array to new Set() should instantiate w/ items', function equal(get(aSet, 'length'), 3, 'should have three items'); aSet.forEach(function(x) { - ok(EnumerableUtils.indexOf(ary, x)>=0, 'should find passed item in array'); + ok(indexOf(ary, x)>=0, 'should find passed item in array'); count++; }); equal(count, 3, 'iterating should have returned three objects'); @@ -97,5 +97,3 @@ QUnit.test('method aliases', function() { equal(aSet.unshift, aSet.addObject, 'unshift -> addObject'); equal(aSet.shift, aSet.pop, 'shift -> pop'); }); - -