From 35c3d81405b7b8199a11176ef60cb8783cc5641a Mon Sep 17 00:00:00 2001 From: tchak Date: Mon, 28 Mar 2016 18:36:32 -0700 Subject: [PATCH] [CLEANUP] Use Array.isArray everywhere instead of Ember.isArray --- addon/-private/system/model/internal-model.js | 2 +- addon/-private/system/store.js | 7 +++---- addon/-private/system/store/finders.js | 4 ++-- addon/-private/system/store/serializer-response.js | 4 ++-- addon/adapters/errors.js | 2 +- tests/integration/adapter/build-url-mixin-test.js | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/addon/-private/system/model/internal-model.js b/addon/-private/system/model/internal-model.js index fbf64a21e28..58501ea5656 100644 --- a/addon/-private/system/model/internal-model.js +++ b/addon/-private/system/model/internal-model.js @@ -578,7 +578,7 @@ InternalModel.prototype = { }, _preloadHasMany(key, preloadValue, type) { - assert("You need to pass in an array to set a hasMany property on a record", Ember.isArray(preloadValue)); + assert("You need to pass in an array to set a hasMany property on a record", Array.isArray(preloadValue)); let recordsToSet = new Array(preloadValue.length); for (let i = 0; i < preloadValue.length; i++) { diff --git a/addon/-private/system/store.js b/addon/-private/system/store.js index 83c24d2c8c0..bf8265b313d 100644 --- a/addon/-private/system/store.js +++ b/addon/-private/system/store.js @@ -59,7 +59,6 @@ export let badIdFormatAssertion = '`id` has to be non-empty string or number'; const Backburner = Ember._Backburner; var Map = Ember.Map; -var isArray = Array.isArray || Ember.isArray; //Get the materialized model from the internalModel/promise that returns //an internal model and return it in a promiseObject. Useful for returning @@ -1658,7 +1657,7 @@ Store = Service.extend({ } } - if (isArray(data.data)) { + if (Array.isArray(data.data)) { length = data.data.length; var internalModels = new Array(length); for (i = 0; i < length; i++) { @@ -2060,7 +2059,7 @@ function deserializeRecordId(store, key, relationship, id) { return; } - assert(`A ${relationship.parentType} record was pushed into the store with the value of ${key} being ${Ember.inspect(id)}, but ${key} is a belongsTo relationship so the value must not be an array. You should probably check your data payload or serializer.`, !isArray(id)); + assert(`A ${relationship.parentType} record was pushed into the store with the value of ${key} being ${Ember.inspect(id)}, but ${key} is a belongsTo relationship so the value must not be an array. You should probably check your data payload or serializer.`, !Array.isArray(id)); //TODO:Better asserts return store._internalModelForId(id.type, id.id); @@ -2071,7 +2070,7 @@ function deserializeRecordIds(store, key, relationship, ids) { return; } - assert(`A ${relationship.parentType} record was pushed into the store with the value of ${key} being '${Ember.inspect(ids)}', but ${key} is a hasMany relationship so the value must be an array. You should probably check your data payload or serializer.`, isArray(ids)); + assert(`A ${relationship.parentType} record was pushed into the store with the value of ${key} being '${Ember.inspect(ids)}', but ${key} is a hasMany relationship so the value must be an array. You should probably check your data payload or serializer.`, Array.isArray(ids)); let _ids = new Array(ids.length); for (let i = 0; i < ids.length; i++) { diff --git a/addon/-private/system/store/finders.js b/addon/-private/system/store/finders.js index 5f8dbed72c8..07c82a99f89 100644 --- a/addon/-private/system/store/finders.js +++ b/addon/-private/system/store/finders.js @@ -17,7 +17,7 @@ import { var Promise = Ember.RSVP.Promise; function payloadIsNotBlank(adapterPayload) { - if (Ember.isArray(adapterPayload)) { + if (Array.isArray(adapterPayload)) { return true; } else { return Object.keys(adapterPayload || {}).length; @@ -175,7 +175,7 @@ export function _query(adapter, store, typeClass, query, recordArray) { records = store.push(payload); }); - assert('The response to store.query is expected to be an array but it was a single record. Please wrap your response in an array or use `store.queryRecord` to query for a single record.', Ember.isArray(records)); + assert('The response to store.query is expected to be an array but it was a single record. Please wrap your response in an array or use `store.queryRecord` to query for a single record.', Array.isArray(records)); recordArray.loadRecords(records, payload); return recordArray; diff --git a/addon/-private/system/store/serializer-response.js b/addon/-private/system/store/serializer-response.js index 9679e4e5903..debad488a22 100644 --- a/addon/-private/system/store/serializer-response.js +++ b/addon/-private/system/store/serializer-response.js @@ -26,7 +26,7 @@ export function validateDocumentStructure(doc) { } } if ('data' in doc) { - if (!(doc.data === null || Ember.isArray(doc.data) || typeof doc.data === 'object')) { + if (!(doc.data === null || Array.isArray(doc.data) || typeof doc.data === 'object')) { errors.push('data must be null, an object, or an array'); } } @@ -36,7 +36,7 @@ export function validateDocumentStructure(doc) { } } if ('errors' in doc) { - if (!Ember.isArray(doc.errors)) { + if (!Array.isArray(doc.errors)) { errors.push('errors must be an array'); } } diff --git a/addon/adapters/errors.js b/addon/adapters/errors.js index 93b8ca1e40c..c8962a8bbb2 100644 --- a/addon/adapters/errors.js +++ b/addon/adapters/errors.js @@ -34,7 +34,7 @@ function extendFn(ErrorClass) { function extend(ParentErrorClass, defaultMessage) { let ErrorClass = function(errors, message) { - assert('`AdapterError` expects json-api formatted errors array.', Ember.isArray(errors || [])); + assert('`AdapterError` expects json-api formatted errors array.', Array.isArray(errors || [])); ParentErrorClass.call(this, errors, message || defaultMessage); }; ErrorClass.prototype = Object.create(ParentErrorClass.prototype); diff --git a/tests/integration/adapter/build-url-mixin-test.js b/tests/integration/adapter/build-url-mixin-test.js index c77edd82c23..7409788f5bc 100644 --- a/tests/integration/adapter/build-url-mixin-test.js +++ b/tests/integration/adapter/build-url-mixin-test.js @@ -226,7 +226,7 @@ test('buildURL - buildURL takes the records from findMany', function(assert) { Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); adapter.buildURL = function(type, ids, snapshots) { - if (Ember.isArray(snapshots)) { + if (Array.isArray(snapshots)) { return "/posts/" + snapshots.get('firstObject').belongsTo('post', { id: true }) + '/comments/'; } return "";