Skip to content

Commit

Permalink
[BUGFIX beta] Deprecate Ember.EnumerableUtils.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed May 27, 2015
1 parent d42eeca commit bd38cb5
Showing 1 changed file with 29 additions and 9 deletions.
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
};

0 comments on commit bd38cb5

Please sign in to comment.