diff --git a/addon/-private/system/identity-map.js b/addon/-private/system/identity-map.js new file mode 100644 index 00000000000..b8ee732850b --- /dev/null +++ b/addon/-private/system/identity-map.js @@ -0,0 +1,28 @@ +import RecordMap from './record-map'; +import EmptyObject from './empty-object'; + +export default class IdentityMap { + constructor() { + this._map = new EmptyObject(); + } + + retrieve(modelName) { + let recordMap = this._map[modelName]; + + if (!recordMap) { + recordMap = this._map[modelName] = new RecordMap(modelName); + } + + return recordMap; + } + + 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(); + } + } +} diff --git a/addon/-private/system/class-meta.js b/addon/-private/system/record-map.js similarity index 71% rename from addon/-private/system/class-meta.js rename to addon/-private/system/record-map.js index 08827179511..96ec61bf954 100644 --- a/addon/-private/system/class-meta.js +++ b/addon/-private/system/record-map.js @@ -1,12 +1,8 @@ import EmptyObject from 'ember-data/-private/system/empty-object'; -const NULL_RESOLUTION = new EmptyObject(); - export default class ClassMeta { - constructor(store, modelName) { + constructor(modelName) { this.modelName = modelName; - this._store = store; - this._modelClass = null; this._idToRecord = null; this._records = null; this._metadata = null; @@ -24,17 +20,9 @@ export default class ClassMeta { return this._metadata || (this._metadata = new EmptyObject()); } - get modelClass() { - if (!this._modelClass) { - this._modelClass = this._store.modelFor(this.modelName) || NULL_RESOLUTION; - } - - return this._modelClass === NULL_RESOLUTION ? null : this._modelClass; - } - /* deprecated way of accessing modelClass */ get type() { - return this.modelClass; + throw new Error('RecordMap.type is no longer available'); } clear() { diff --git a/addon/-private/system/store.js b/addon/-private/system/store.js index d5bf3c429de..afc8a2471b7 100644 --- a/addon/-private/system/store.js +++ b/addon/-private/system/store.js @@ -7,7 +7,7 @@ import Model from 'ember-data/model'; import { instrument, assert, deprecate, warn, runInDebug } from "ember-data/-private/debug"; import normalizeModelName from "ember-data/-private/system/normalize-model-name"; import { InvalidError } from 'ember-data/adapters/errors'; -import ClassMeta from 'ember-data/-private/system/class-meta'; +import IdentityMap from 'ember-data/-private/system/identity-map'; import { promiseArray, promiseObject @@ -213,7 +213,7 @@ Store = Service.extend({ store: this }); - this._recordMaps = new EmptyObject(); + this._identityMap = new IdentityMap(); this._pendingSave = []; this._instanceCache = new ContainerInstanceCache(getOwner(this), this); @@ -1665,13 +1665,7 @@ Store = Service.extend({ assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ inspect(modelName), !modelName || typeof modelName === 'string'); if (arguments.length === 0) { - let recordMaps = this._recordMaps; - let keys = Object.keys(recordMaps); - - for (let i = 0; i < keys.length; i++) { - let key = keys[i]; - recordMaps[key].clear(); - } + this._identityMap.clear(); } else { let trueModelName = this._classKeyFor(modelName); this._recordMapFor(trueModelName).clear(); @@ -1975,15 +1969,7 @@ Store = Service.extend({ */ _recordMapFor(modelName) { heimdall.increment(_recordMapFor); - let recordMaps = this._recordMaps; - let recordMap = recordMaps[modelName]; - - if (recordMap) { return recordMap; } - - recordMap = new ClassMeta(this, modelName); - recordMaps[modelName] = recordMap; - - return recordMap; + return this._identityMap.retrieve(modelName); }, // ................