Skip to content

Commit

Permalink
Merge pull request #4284 from tchak/is-array
Browse files Browse the repository at this point in the history
[CLEANUP] Use Array.isArray everywhere instead of Ember.isArray
  • Loading branch information
bmac committed Mar 29, 2016
2 parents fe3be96 + 35c3d81 commit fd053c9
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
7 changes: 3 additions & 4 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
Expand All @@ -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++) {
Expand Down
4 changes: 2 additions & 2 deletions addon/-private/system/store/finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions addon/-private/system/store/serializer-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand All @@ -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');
}
}
Expand Down
2 changes: 1 addition & 1 deletion addon/adapters/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/adapter/build-url-mixin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down

0 comments on commit fd053c9

Please sign in to comment.