-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for early subscribers not being updated when a store is ready
- Loading branch information
1 parent
7811a0d
commit 568958e
Showing
4 changed files
with
130 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,47 @@ | ||
import { StorageAdapter, StorageKey } from "@automerge/automerge-repo"; | ||
|
||
export class DummyStorageAdapter implements StorageAdapter { | ||
#data: Record<string, Uint8Array> = {}; | ||
|
||
#keyToString(key: string[]): string { | ||
return key.join("."); | ||
} | ||
|
||
#stringToKey(key: string): string[] { | ||
return key.split("."); | ||
} | ||
|
||
async loadRange( | ||
keyPrefix: StorageKey, | ||
): Promise<{ data: Uint8Array; key: StorageKey }[]> { | ||
const range = Object.entries(this.#data) | ||
.filter(([key, _]) => key.startsWith(this.#keyToString(keyPrefix))) | ||
.map(([key, data]) => ({ key: this.#stringToKey(key), data })); | ||
return Promise.resolve(range); | ||
} | ||
|
||
async removeRange(keyPrefix: string[]): Promise<void> { | ||
Object.entries(this.#data) | ||
.filter(([key, _]) => key.startsWith(this.#keyToString(keyPrefix))) | ||
.forEach(([key, _]) => delete this.#data[key]); | ||
} | ||
|
||
async load(key: string[]): Promise<Uint8Array | undefined> { | ||
return new Promise((resolve) => | ||
resolve(this.#data[this.#keyToString(key)]), | ||
); | ||
} | ||
|
||
async save(key: string[], binary: Uint8Array) { | ||
this.#data[this.#keyToString(key)] = binary; | ||
return Promise.resolve(); | ||
} | ||
|
||
async remove(key: string[]) { | ||
delete this.#data[this.#keyToString(key)]; | ||
} | ||
|
||
keys() { | ||
return Object.keys(this.#data); | ||
} | ||
} |
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