Skip to content

Commit 9a8e1d2

Browse files
authored
Add simple Identity Map (#73)
* When persisted, model instances are registered with an in-memory store. When deleted, they are removed from the store and the new `stale` property becomes `true`. * Model attributes can now be synced across instances. If assigning an attribute, that attribute will not be synced until save. After save, all instances of that Model will sync attributes. * In order to sync attributes, we listen for updates from the central store. This means to be garbage collected the listener must be removed. You can do this by calling `model.unlisten()`. Framework-specific libraries will ensure `unlisten()` is called automatically when the framework no longer references the instance. * When associations return related objects, they remove anything that was deleted from the store. This way `await book.destroy()` will affect the `author.books` relationship. Because the behavior of modifying instances out from under you can be seen as an implicit (and possibly undesired) side-effect, this behavior is opt-in: ```ts // ApplicationRecord static sync = true ```
1 parent b24d582 commit 9a8e1d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1189
-131
lines changed

lib-esm/associations.js

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib-esm/associations.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib-esm/attribute.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib-esm/attribute.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib-esm/local-storage.d.ts renamed to lib-esm/credential-storage.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export declare class NullStorageBackend implements StorageBackend {
88
setItem(key: string, value: string | undefined): void;
99
removeItem(key: string): void;
1010
}
11-
export declare class LocalStorage {
11+
export declare class CredentialStorage {
1212
private _jwtKey;
1313
private _backend;
1414
constructor(jwtKey: string | false, backend?: StorageBackend);

lib-esm/local-storage.js renamed to lib-esm/credential-storage.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)