Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
igorT committed Jun 1, 2015
1 parent cf1b2d5 commit 077d939
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 38 deletions.
8 changes: 4 additions & 4 deletions packages/ember-data/lib/system/many-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {

flushCanonical: function() {
//TODO make this smarter, currently its plenty stupid
var toSet = filter.call(this.canonicalState, function(record) {
return !record.isDeleted();
var toSet = filter.call(this.canonicalState, function(internalModel) {
return !internalModel.isDeleted();
});

//a hack for not removing new records
//TODO remove once we have proper diffing
var newRecords = this.currentState.filter(function(record) {
return record.isNew();
var newRecords = this.currentState.filter(function(internalModel) {
return internalModel.isNew();
});
toSet = toSet.concat(newRecords);
var oldLength = this.length;
Expand Down
7 changes: 5 additions & 2 deletions packages/ember-data/lib/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function retrieveFromCurrentState(key) {
};
}

/*
/**
`InternalModel` is the Model class that we use internally inside Ember Data to represent models.
Internal ED methods should only deal with `InternalModel` objects. It is a fast, plain Javascript class.
Expand All @@ -43,9 +43,11 @@ function retrieveFromCurrentState(key) {
We need to make sure that the properties from `InternalModel` are correctly exposed/proxied on `Model`
if they are needed.
@class InternalModel
*/

var InternalModel = function(type, id, store, container, data) {
var InternalModel = function InternalModel(type, id, store, container, data) {
this.type = type;
this.id = id;
this.store = store;
Expand All @@ -60,6 +62,7 @@ var InternalModel = function(type, id, store, container, data) {
this._inFlightAttributes = Ember.create(null);
this._relationships = {};
this.currentState = RootState.empty;
this.isReloading = false;
/*
implicit relationships are relationship which have not been declared but the inverse side exists on
another record somewhere
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export default RecordArray.extend({
var meta = store.metadataFor(type);

//TODO Optimize
var refs = Ember.A(records).mapBy('_internalModel');
var internalModels = Ember.A(records).mapBy('_internalModel');
this.setProperties({
content: Ember.A(refs),
content: Ember.A(internalModels),
isLoaded: true,
meta: cloneNull(meta)
});

refs.forEach(function(record) {
internalModels.forEach(function(record) {
this.manager.recordArraysForRecord(record).add(this);
}, this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ BelongsToRelationship.prototype.removeCanonicalRecordFromOwn = function(record)

BelongsToRelationship.prototype.findRecord = function() {
if (this.inverseRecord) {
return this.store._findByRecord(this.inverseRecord);
return this.store._findByInternalModel(this.inverseRecord);
} else {
return Ember.RSVP.Promise.resolve(null);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-data/lib/system/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Snapshot(internalModel) {
this._attributes[keyName] = get(record, keyName);
}, this);

this.id = get(internalModel, 'id');
this.id = internalModel.id;
this._internalModel = internalModel;
this.type = internalModel.type;
this.modelName = internalModel.type.modelName;
Expand Down
32 changes: 5 additions & 27 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ Store = Service.extend({
var type = this.modelFor(modelName);
var internalModel = this._internalModelForId(type, id);

return this._findByRecord(internalModel, preload);
return this._findByInternalModel(internalModel, preload);
},

_findByInternalModel: function(internalModel, preload) {
Expand All @@ -637,25 +637,6 @@ Store = Service.extend({

return promiseRecord(fetchedInternalModel || internalModel, "DS: Store#findByRecord " + internalModel.typeKey + " with id: " + get(internalModel, 'id'));
},


_findByRecord: function(record, preload) {
var fetchedRecord;

if (preload) {
record._preloadData(preload);
}

if (record.isEmpty()) {
fetchedRecord = this.scheduleFetch(record);
//TODO double check about reloading
} else if (record.isLoading()) {
fetchedRecord = record._loadingPromise;
}

return promiseRecord(fetchedRecord || record, "DS: Store#findByRecord " + record.modelName + " with id: " + get(record, 'id'));
},

/**
This method makes a series of requests to the adapter's `find` method
and returns a promise that resolves once they are all loaded.
Expand Down Expand Up @@ -922,16 +903,13 @@ Store = Service.extend({
/**
@method findMany
@private
@param {DS.Model} owner
@param {Array} records
@param {String or subclass of DS.Model} type
@param {Resolver} resolver
@param {Array} internalModels
@return {Promise} promise
*/
findMany: function(records) {
findMany: function(internalModels) {
var store = this;
return Promise.all(map(records, function(record) {
return store._findByRecord(record);
return Promise.all(map(internalModels, function(internalModel) {
return store._findByInternalModel(internalModel);
}));
},

Expand Down

0 comments on commit 077d939

Please sign in to comment.