Skip to content

Commit

Permalink
Merge pull request #3147 from tchak/internal-model-cleanup
Browse files Browse the repository at this point in the history
more cleanup on internalModel vs record
  • Loading branch information
igorT committed Jun 2, 2015
2 parents 9d1b970 + e5de2c5 commit 37401a8
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 209 deletions.
2 changes: 1 addition & 1 deletion packages/ember-data/lib/system/model/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function getDefaultValue(record, options, key) {
function hasValue(record, key) {
return key in record._attributes ||
key in record._inFlightAttributes ||
record._data.hasOwnProperty(key);
key in record._data;
}

function getValue(record, key) {
Expand Down
17 changes: 12 additions & 5 deletions packages/ember-data/lib/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ var InternalModel = function InternalModel(type, id, store, container, data) {
this.id = id;
this.store = store;
this.container = container;
this._data = data || {};
this._data = data || Ember.create(null);
this.modelName = type.modelName;
this.errors = null;
this.dataHasInitialized = false;
//Look into making this lazy
this._deferredTriggers = [];
this._data = {};
this._attributes = Ember.create(null);
this._inFlightAttributes = Ember.create(null);
this._relationships = {};
this._relationships = Ember.create(null);
this.currentState = RootState.empty;
this.isReloading = false;
/*
Expand Down Expand Up @@ -215,10 +214,10 @@ InternalModel.prototype = {
},

/**
@method _createSnapshot
@method createSnapshot
@private
*/
_createSnapshot: function() {
createSnapshot: function() {
return new Snapshot(this);
},

Expand Down Expand Up @@ -660,6 +659,14 @@ InternalModel.prototype = {
}
}
this._inFlightAttributes = Ember.create(null);
},

toString: function() {
if (this.record) {
return this.record.toString();
} else {
return `<${this.modelName}:${this.id}>`;
}
}
};

Expand Down
11 changes: 3 additions & 8 deletions packages/ember-data/lib/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ var Model = Ember.Object.extend(Ember.Evented, {
toJSON: function(options) {
// container is for lazy transform lookups
var serializer = JSONSerializer.create({ container: this.container });
var snapshot = this._createSnapshot();
var snapshot = this._internalModel.createSnapshot();

return serializer.serialize(snapshot, options);
},
Expand Down Expand Up @@ -444,11 +444,7 @@ var Model = Ember.Object.extend(Ember.Evented, {
@private
@type {Object}
*/
data: Ember.computed(function() {
this._data = this._data || {};
return this._data;
}).readOnly(),

data: Ember.computed.readOnly('_internalModel._data'),

//TODO Do we want to deprecate these?
/**
Expand Down Expand Up @@ -624,13 +620,12 @@ var Model = Ember.Object.extend(Ember.Evented, {
this._internalModel.rollback();
},


/*
@method _createSnapshot
@private
*/
_createSnapshot: function() {
return this._internalModel._createSnapshot();
return this._internalModel.createSnapshot();
},

toStringExtension: function() {
Expand Down
Loading

0 comments on commit 37401a8

Please sign in to comment.