Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLEANUP Beta] isArray Prefer Array.isArray for ember-metal variant, … #11463

Merged
merged 1 commit into from
Jun 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/ember-htmlbars/lib/helpers/-bind-attr-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
*/

import { get } from 'ember-metal/property_get';
import { isArray } from 'ember-metal/utils';

export default function bindAttrClassHelper(params) {
var value = params[0];

if (isArray(value)) {
if (Array.isArray(value)) {
value = get(value, 'length') !== 0;
}

Expand Down
3 changes: 1 addition & 2 deletions packages/ember-metal/lib/get_properties.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { get } from 'ember-metal/property_get';
import { isArray } from 'ember-metal/utils';

/**
To get multiple properties at once, call `Ember.getProperties`
Expand Down Expand Up @@ -29,7 +28,7 @@ export default function getProperties(obj) {
var propertyNames = arguments;
var i = 1;

if (arguments.length === 2 && isArray(arguments[1])) {
if (arguments.length === 2 && Array.isArray(arguments[1])) {
i = 0;
propertyNames = arguments[1];
}
Expand Down
5 changes: 2 additions & 3 deletions packages/ember-metal/lib/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import {
guidFor,
meta as metaFor,
wrap,
makeArray,
isArray
makeArray
} from 'ember-metal/utils';
import expandProperties from 'ember-metal/expand_properties';
import {
Expand Down Expand Up @@ -221,7 +220,7 @@ function applyConcatenatedProperties(obj, key, value, values) {
function applyMergedProperties(obj, key, value, values) {
var baseValue = values[key] || obj[key];

Ember.assert(`You passed in \`${JSON.stringify(value)}\` as the value for \`${key}\` but \`${key}\` cannot be an Array`, !isArray(value));
Ember.assert(`You passed in \`${JSON.stringify(value)}\` as the value for \`${key}\` but \`${key}\` cannot be an Array`, !Array.isArray(value));

if (!baseValue) { return value; }

Expand Down
13 changes: 2 additions & 11 deletions packages/ember-metal/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,6 @@ var deprecatedTryCatchFinally = function() {

var toString = Object.prototype.toString;

var isArray = Array.isArray || function(value) {
return value !== null &&
value !== undefined &&
typeof value === 'object' &&
typeof value.length === 'number' &&
toString.call(value) === '[object Array]';
};

/**
Forces the passed object to be part of an array. If the object is already
an array, it will return the object. Otherwise, it will add the object to
Expand All @@ -752,7 +744,7 @@ var isArray = Array.isArray || function(value) {
*/
export function makeArray(obj) {
if (obj === null || obj === undefined) { return []; }
return isArray(obj) ? obj : [obj];
return Array.isArray(obj) ? obj : [obj];
}

/**
Expand All @@ -776,7 +768,7 @@ export function inspect(obj) {
if (obj === undefined) {
return 'undefined';
}
if (isArray(obj)) {
if (Array.isArray(obj)) {
return '[' + obj + ']';
}
// for non objects
Expand Down Expand Up @@ -853,7 +845,6 @@ export {
META_DESC,
EMPTY_META,
meta,
isArray,
makeArray,
tryCatchFinally,
deprecatedTryCatchFinally,
Expand Down
5 changes: 2 additions & 3 deletions packages/ember-metal/lib/watch_key.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import isEnabled from 'ember-metal/features';
import {
meta as metaFor,
isArray
meta as metaFor
} from 'ember-metal/utils';
import {
MANDATORY_SETTER_FUNCTION,
Expand All @@ -10,7 +9,7 @@ import {

export function watchKey(obj, keyName, meta) {
// can't watch length on Array - it is special...
if (keyName === 'length' && isArray(obj)) { return; }
if (keyName === 'length' && Array.isArray(obj)) { return; }

var m = meta || metaFor(obj);
var watching = m.watching;
Expand Down
5 changes: 2 additions & 3 deletions packages/ember-metal/lib/watch_path.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
meta as metaFor,
isArray
meta as metaFor
} from 'ember-metal/utils';
import { ChainNode } from 'ember-metal/chains';

Expand All @@ -20,7 +19,7 @@ function chainsFor(obj, meta) {

export function watchPath(obj, keyPath, meta) {
// can't watch length on Array - it is special...
if (keyPath === 'length' && isArray(obj)) { return; }
if (keyPath === 'length' && Array.isArray(obj)) { return; }

var m = meta || metaFor(obj);
var watching = m.watching;
Expand Down
8 changes: 2 additions & 6 deletions packages/ember-metal/lib/watching.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
@module ember-metal
*/

import {
isArray
} from 'ember-metal/utils';
import {
removeChainWatcher,
flushPendingChains
Expand All @@ -17,7 +14,6 @@ import {
watchPath,
unwatchPath
} from 'ember-metal/watch_path';

import {
isPath
} from 'ember-metal/path_cache';
Expand All @@ -37,7 +33,7 @@ import {
*/
function watch(obj, _keyPath, m) {
// can't watch length on Array - it is special...
if (_keyPath === 'length' && isArray(obj)) { return; }
if (_keyPath === 'length' && Array.isArray(obj)) { return; }

if (!isPath(_keyPath)) {
watchKey(obj, _keyPath, m);
Expand All @@ -57,7 +53,7 @@ watch.flushPending = flushPendingChains;

export function unwatch(obj, _keyPath, m) {
// can't watch length on Array - it is special...
if (_keyPath === 'length' && isArray(obj)) { return; }
if (_keyPath === 'length' && Array.isArray(obj)) { return; }

if (!isPath(_keyPath)) {
unwatchKey(obj, _keyPath, m);
Expand Down
5 changes: 2 additions & 3 deletions packages/ember-routing/lib/system/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import isNone from 'ember-metal/is_none';
import { computed } from 'ember-metal/computed';
import merge from 'ember-metal/merge';
import {
isArray,
typeOf
} from 'ember-runtime/utils';
import run from 'ember-metal/run_loop';
Expand Down Expand Up @@ -172,7 +171,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
var urlKey = desc.as || this.serializeQueryParamKey(propName);
var defaultValue = get(controllerProto, propName);

if (isArray(defaultValue)) {
if (Array.isArray(defaultValue)) {
defaultValue = Ember.A(defaultValue.slice());
}

Expand Down Expand Up @@ -2198,7 +2197,7 @@ function getQueryParamsFor(route, state) {
}

function copyDefaultValue(value) {
if (isArray(value)) {
if (Array.isArray(value)) {
return Ember.A(value.slice());
}
return value;
Expand Down
5 changes: 2 additions & 3 deletions packages/ember-runtime/lib/computed/reduce_computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import Ember from 'ember-metal/core'; // Ember.assert
import { get as e_get } from 'ember-metal/property_get';
import {
guidFor,
meta as metaFor,
isArray
meta as metaFor
} from 'ember-metal/utils';
import EmberError from 'ember-metal/error';
import {
Expand Down Expand Up @@ -520,7 +519,7 @@ function ReduceComputedProperty(options) {
Ember.assert(
'dependent array ' + dependentKey + ' must be an `Ember.Array`. ' +
'If you are not extending arrays, you will need to wrap native arrays with `Ember.A`',
!(isArray(get(this, dependentKey)) && !EmberArray.detect(get(this, dependentKey))));
!(Array.isArray(get(this, dependentKey)) && !EmberArray.detect(get(this, dependentKey))));

if (!partiallyRecomputeFor(this, dependentKey)) { return; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import Ember from 'ember-metal/core'; // Ember.assert
import { get } from 'ember-metal/property_get';
import {
isArray,
guidFor
} from 'ember-metal/utils';
import EmberError from 'ember-metal/error';
Expand Down Expand Up @@ -772,7 +771,7 @@ function propertySort(itemsKey, sortPropertiesKey) {
var sortProperty, idx, asc;

Ember.assert('Cannot sort: \'' + sortPropertiesKey + '\' is not an array.',
isArray(sortPropertyDefinitions));
Array.isArray(sortPropertyDefinitions));

changeMeta.property.clearItemPropertyKeys(itemsKey);

Expand Down
3 changes: 1 addition & 2 deletions packages/ember-runtime/lib/copy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Ember from 'ember-metal/core';
import { isArray } from 'ember-metal/utils';
import EmberObject from 'ember-runtime/system/object';
import Copyable from 'ember-runtime/mixins/copyable';

Expand All @@ -21,7 +20,7 @@ function _copy(obj, deep, seen, copies) {

// IMPORTANT: this specific test will detect a native array only. Any other
// object will need to implement Copyable.
if (isArray(obj)) {
if (Array.isArray(obj)) {
ret = obj.slice();

if (deep) {
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-runtime/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import RSVP from 'ember-runtime/ext/rsvp'; // just for side effect of extend
import 'ember-runtime/ext/string'; // just for side effect of extending String.prototype
import 'ember-runtime/ext/function'; // just for side effect of extending Function.prototype

import { typeOf, isArray } from 'ember-runtime/utils';
import { typeOf } from 'ember-runtime/utils';
// END IMPORTS

// BEGIN EXPORTS
Expand Down Expand Up @@ -117,8 +117,8 @@ Ember.ArrayComputedProperty = ArrayComputedProperty;
Ember.reduceComputed = reduceComputed;
Ember.ReduceComputedProperty = ReduceComputedProperty;

Ember.typeOf = typeOf;
Ember.isArray = isArray;
Ember.typeOf = typeOf;
Ember.isArray = Array.isArray;

// ES6TODO: this seems a less than ideal way/place to add properties to Ember.computed
var EmComputed = Ember.computed;
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-runtime/lib/mixins/mutable_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ var EMPTY = [];
//

import { get } from 'ember-metal/property_get';
import { isArray } from 'ember-metal/utils';
import EmberError from 'ember-metal/error';
import { Mixin } from 'ember-metal/mixin';
import EmberArray from 'ember-runtime/mixins/array';
import MutableEnumerable from 'ember-runtime/mixins/mutable_enumerable';
import Enumerable from 'ember-runtime/mixins/enumerable';

/**
This mixin defines the API for modifying array-like objects. These methods
can be applied only to a collection that keeps its items in an ordered set.
Expand Down Expand Up @@ -194,7 +194,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, {
@public
*/
pushObjects(objects) {
if (!(Enumerable.detect(objects) || isArray(objects))) {
if (!(Enumerable.detect(objects) || Array.isArray(objects))) {
throw new TypeError('Must pass Ember.Enumerable to Ember.MutableArray#pushObjects');
}
this.replace(get(this, 'length'), 0, objects);
Expand Down
3 changes: 1 addition & 2 deletions packages/ember-runtime/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import EmberArray from 'ember-runtime/mixins/array';
import EmberObject from 'ember-runtime/system/object';
import {isArray as _isArray} from 'ember-metal/utils';

// ........................................
// TYPING & ARRAY MESSAGING
Expand Down Expand Up @@ -44,7 +43,7 @@ var toString = Object.prototype.toString;
*/
export function isArray(obj) {
if (!obj || obj.setInterval) { return false; }
if (_isArray(obj)) { return true; }
if (Array.isArray(obj)) { return true; }
if (EmberArray.detect(obj)) { return true; }

let type = typeOf(obj);
Expand Down
7 changes: 2 additions & 5 deletions packages/ember-views/lib/mixins/class_names_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import Ember from 'ember-metal/core';
import { Mixin } from 'ember-metal/mixin';
import { A as emberA } from 'ember-runtime/system/native_array';
import {
isArray
} from 'ember-metal/utils';

var EMPTY_ARRAY = [];

Expand All @@ -22,10 +19,10 @@ export default Mixin.create({
init() {
this._super(...arguments);

Ember.assert('Only arrays are allowed for \'classNameBindings\'', isArray(this.classNameBindings));
Ember.assert(`Only arrays are allowed for 'classNameBindings'`, Array.isArray(this.classNameBindings));
this.classNameBindings = emberA(this.classNameBindings.slice());

Ember.assert('Only arrays of static class strings are allowed for \'classNames\'. For dynamic classes, use \'classNameBindings\'.', isArray(this.classNames));
Ember.assert(`Only arrays of static class strings are allowed for 'classNames'. For dynamic classes, use 'classNameBindings'.`, Array.isArray(this.classNames));
this.classNames = emberA(this.classNames.slice());
},

Expand Down