Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
igorT committed Jun 2, 2015
1 parent 077d939 commit 2b14367
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions packages/ember-data/lib/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -504,7 +502,7 @@ InternalModel.prototype = {
if (relationshipMeta.isRelationship) {
record._preloadRelationship(key, preloadValue);
} else {
get(record, '_data')[key] = preloadValue;
record._data[key] = preloadValue;
}
});
},
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
},

Expand Down

0 comments on commit 2b14367

Please sign in to comment.