-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor typeMap => recordMap and refactor to using modelName instead…
… of guid as the class identifier for recordMap
- Loading branch information
Showing
19 changed files
with
514 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.