From f01bb69139b1c44539e63bcbcb81b2cbfb1e5462 Mon Sep 17 00:00:00 2001 From: Trent Willis Date: Mon, 26 Oct 2015 11:23:40 -0700 Subject: [PATCH] Use for-loops instead of Array prototype methods in store#push --- packages/ember-data/lib/system/store.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/ember-data/lib/system/store.js b/packages/ember-data/lib/system/store.js index bfb09bd8c92..69df7824590 100644 --- a/packages/ember-data/lib/system/store.js +++ b/packages/ember-data/lib/system/store.js @@ -53,6 +53,7 @@ export let badIdFormatAssertion = '`id` has to be non-empty string or number'; var Backburner = Ember._Backburner || Ember.Backburner || Ember.__loader.require('backburner')['default'] || Ember.__loader.require('backburner')['Backburner']; var Map = Ember.Map; +var isArray = Array.isArray || Ember.isArray; //Shim Backburner.join if (!Backburner.prototype.join) { @@ -1672,13 +1673,21 @@ Store = Service.extend({ updated. */ push: function(data) { - if (data.included) { - data.included.forEach((recordData) => this._pushInternalModel(recordData)); + var included = data.included; + var i, length; + if (included) { + for (i = 0, length = included.length; i < length; i++) { + this._pushInternalModel(included[i]); + } } - if (Ember.typeOf(data.data) === 'array') { - var internalModels = data.data.map((recordData) => this._pushInternalModel(recordData)); - return internalModels.map((internalModel) => internalModel.getRecord()); + if (isArray(data.data)) { + length = data.data.length; + var internalModels = new Array(length); + for (i = 0; i < length; i++) { + internalModels[i] = this._pushInternalModel(data.data[i]).getRecord(); + } + return internalModels; } var internalModel = this._pushInternalModel(data.data || data); @@ -2046,7 +2055,7 @@ function deserializeRecordId(store, key, relationship, id) { return; } - Ember.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.`, !Ember.isArray(id)); + Ember.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)); //TODO:Better asserts return store._internalModelForId(id.type, id.id); @@ -2057,7 +2066,7 @@ function deserializeRecordIds(store, key, relationship, ids) { return; } - Ember.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.`, Ember.isArray(ids)); + Ember.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)); return ids.map((id) => deserializeRecordId(store, key, relationship, id)); }