Skip to content

Commit

Permalink
Merge pull request #11286 from rwjblue/enumerable_utils-deprecation
Browse files Browse the repository at this point in the history
[BUGFIX beta] Deprecate Ember.EnumerableUtils.
  • Loading branch information
rwjblue committed May 27, 2015
2 parents d42eeca + 3521d8e commit a0acc6e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/ember-application/lib/system/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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');
});

Expand Down
38 changes: 29 additions & 9 deletions packages/ember-metal/lib/enumerable_utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Ember from 'ember-metal/core'; // Ember.deprecateFunc
import {
filter as _filter,
forEach as a_forEach,
Expand All @@ -13,6 +14,7 @@ var splice = Array.prototype.splice;
*
* @class EnumerableUtils
* @namespace Ember
* @deprecated
* @static
* */

Expand All @@ -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*
Expand All @@ -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*
Expand All @@ -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*
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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*
*
Expand All @@ -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
*
Expand All @@ -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.
*
Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
*
Expand All @@ -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
};
4 changes: 2 additions & 2 deletions packages/ember-metal/tests/platform/define_property_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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()");
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-runtime/lib/system/subarray.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-runtime/tests/suites/enumerable/map.js
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions packages/ember-runtime/tests/system/set/extra_test.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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');
Expand Down Expand Up @@ -97,5 +97,3 @@ QUnit.test('method aliases', function() {
equal(aSet.unshift, aSet.addObject, 'unshift -> addObject');
equal(aSet.shift, aSet.pop, 'shift -> pop');
});


0 comments on commit a0acc6e

Please sign in to comment.