-
-
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.
feat: Store.cache and Store.createCache (#8458)
* cleanup * add docs * fixes * more fixes * more progress * fixes * all the fixes * fix docs * fix more tests
- Loading branch information
Showing
21 changed files
with
661 additions
and
1,154 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
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
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
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
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,34 @@ | ||
import { assert } from '@ember/debug'; | ||
|
||
import type { Cache } from '@ember-data/types/q/cache'; | ||
import type { StableRecordIdentifier } from '@ember-data/types/q/identifier'; | ||
import type { RecordInstance } from '@ember-data/types/q/record-instance'; | ||
|
||
/* | ||
* Returns the Cache instance associated with a given | ||
* Model or Identifier | ||
*/ | ||
|
||
export const CacheForIdentifierCache = new Map<StableRecordIdentifier | RecordInstance, Cache>(); | ||
|
||
export function setCacheFor(identifier: StableRecordIdentifier | RecordInstance, recordData: Cache): void { | ||
assert( | ||
`Illegal set of identifier`, | ||
!CacheForIdentifierCache.has(identifier) || CacheForIdentifierCache.get(identifier) === recordData | ||
); | ||
CacheForIdentifierCache.set(identifier, recordData); | ||
} | ||
|
||
export function removeRecordDataFor(identifier: StableRecordIdentifier | RecordInstance): void { | ||
CacheForIdentifierCache.delete(identifier); | ||
} | ||
|
||
export default function peekCache(instance: StableRecordIdentifier): Cache | null; | ||
export default function peekCache(instance: RecordInstance): Cache; | ||
export default function peekCache(instance: StableRecordIdentifier | RecordInstance): Cache | null { | ||
if (CacheForIdentifierCache.has(instance as StableRecordIdentifier)) { | ||
return CacheForIdentifierCache.get(instance as StableRecordIdentifier) as Cache; | ||
} | ||
|
||
return null; | ||
} |
Oops, something went wrong.