From 2b14367d1870ffa2f7ae30b3ccd1f8a8ffccc340 Mon Sep 17 00:00:00 2001 From: IgorT Date: Tue, 2 Jun 2015 03:07:25 +0300 Subject: [PATCH] cleanup --- .../lib/system/model/internal-model.js | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/packages/ember-data/lib/system/model/internal-model.js b/packages/ember-data/lib/system/model/internal-model.js index 2cb9f9d5c46..ddc4c7a90e2 100644 --- a/packages/ember-data/lib/system/model/internal-model.js +++ b/packages/ember-data/lib/system/model/internal-model.js @@ -104,6 +104,7 @@ InternalModel.prototype = { constructor: InternalModel, materializeRecord: function() { + Ember.assert(this.record === null, "Materialized " + this.modelName + " record with id:" + this.id + "more than once"); // lookupFactory should really return an object that creates // instances with the injections applied this.record = this.type._create({ @@ -158,7 +159,7 @@ InternalModel.prototype = { }, function(reason) { record.didError(); throw reason; - }, "DS: Model#reload complete, update flags")['finally'](function () { + }, "DS: Model#reload complete, update flags").finally(function () { record.finishedReloading(); record.updateRecordArrays(); }); @@ -197,10 +198,7 @@ InternalModel.prototype = { }, becameReady: function() { - var self = this; - Ember.run.schedule('actions', function() { - self.store.recordArrayManager.recordWasLoaded(self); - }); + Ember.run.schedule('actions', this.store.recordArrayManager, this.store.recordArrayManager.recordWasLoaded, this); }, didInitalizeData: function() { @@ -423,7 +421,7 @@ InternalModel.prototype = { if (this._deferredTriggers.push(args) !== 1) { return; } - Ember.run.schedule('actions', this, '_triggerDeferredTriggers'); + Ember.run.scheduleOnce('actions', this, '_triggerDeferredTriggers'); }, _triggerDeferredTriggers: function() { @@ -504,7 +502,7 @@ InternalModel.prototype = { if (relationshipMeta.isRelationship) { record._preloadRelationship(key, preloadValue); } else { - get(record, '_data')[key] = preloadValue; + record._data[key] = preloadValue; } }); }, @@ -521,10 +519,10 @@ InternalModel.prototype = { _preloadHasMany: function(key, preloadValue, type) { Ember.assert("You need to pass in an array to set a hasMany property on a record", Ember.isArray(preloadValue)); - var record = this; + var internalModel = this; var recordsToSet = map.call(preloadValue, function(recordToPush) { - return record._convertStringOrNumberIntoInternalModel(recordToPush, type); + return internalModel._convertStringOrNumberIntoInternalModel(recordToPush, type); }); //We use the pathway of setting the hasMany as if it came from the adapter //because the user told us that they know this relationships exists already @@ -540,7 +538,7 @@ InternalModel.prototype = { }, _convertStringOrNumberIntoInternalModel: function(value, type) { - if (Ember.typeOf(value) === 'string' || Ember.typeOf(value) === 'number') { + if (typeof value === 'string' || typeof value === 'number') { return this.store._internalModelForId(type, value); } if (value._internalModel) { @@ -639,12 +637,9 @@ InternalModel.prototype = { */ adapterDidInvalidate: function(errors) { var recordErrors = this.getErrors(); - for (var key in errors) { - if (!errors.hasOwnProperty(key)) { - continue; - } + forEach.call(Ember.keys(errors), (key) => { recordErrors.add(key, errors[key]); - } + }); this._saveWasRejected(); },