Skip to content

Commit

Permalink
refactor typeMap => recordMap and refactor to using modelName instead…
Browse files Browse the repository at this point in the history
… of guid as the class identifier for recordMap
  • Loading branch information
runspired committed Dec 12, 2016
1 parent 7fd36c4 commit 22971f9
Show file tree
Hide file tree
Showing 19 changed files with 514 additions and 316 deletions.
49 changes: 49 additions & 0 deletions addon/-private/system/identity-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import RecordMap from './record-map';

/**
`IdentityMap` is a custom storage map for records by modelName
used by `DS.Store`.
@class IdentityMap
@private
*/
export default class IdentityMap {
constructor() {
this._map = Object.create(null);
}

/**
Retrieves the `RecordMap` for a given modelName,
creating one if one did not already exist. This is
similar to `getWithDefault` or `get` on a `MapWithDefault`
@method retrieve
@param modelName a previously normalized modelName
@returns {RecordMap} the RecordMap for the given modelName
*/
retrieve(modelName) {
let recordMap = this._map[modelName];

if (!recordMap) {
recordMap = this._map[modelName] = new RecordMap(modelName);
}

return recordMap;
}

/**
Clears the contents of all known `RecordMaps`, but does
not remove the RecordMap instances.
@method clear
*/
clear() {
let recordMaps = this._map;
let keys = Object.keys(recordMaps);

for (let i = 0; i < keys.length; i++) {
let key = keys[i];
recordMaps[key].clear();
}
}
}
15 changes: 11 additions & 4 deletions addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ const {
'updateChangedAttributes'
);

let InternalModelReferenceId = 1;

/*
`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 @@ -104,13 +106,13 @@ const {
@class InternalModel
*/
export default class InternalModel {
constructor(modelClass, id, store, data) {
constructor(modelName, id, store, data) {
heimdall.increment(new_InternalModel);
this.modelClass = modelClass;
this.id = id;
this._internalId = InternalModelReferenceId++;
this.store = store;
this._data = data || new EmptyObject();
this.modelName = modelClass.modelName;
this.modelName = modelName;
this.dataHasInitialized = false;
this._loadingPromise = null;
this._recordArrays = undefined;
Expand All @@ -122,6 +124,7 @@ export default class InternalModel {
this.error = null;

// caches for lazy getters
this._modelClass = null;
this.__deferredTriggers = null;
this._references = null;
this._recordReference = null;
Expand All @@ -131,6 +134,10 @@ export default class InternalModel {
this.__implicitRelationships = null;
}

get modelClass() {
return this._modelClass || (this._modelClass = this.store.modelFor(this.modelName));
}

get type() {
return this.modelClass;
}
Expand Down Expand Up @@ -778,7 +785,7 @@ export default class InternalModel {
*/
updateRecordArrays() {
this._updatingRecordArraysLater = false;
this.store.dataWasUpdated(this.modelClass, this);
this.store._dataWasUpdated(this);
}

setId(id) {
Expand Down
Loading

0 comments on commit 22971f9

Please sign in to comment.