This commit is contained in:
2023-09-21 21:02:59 +01:00
parent 4b57d57f94
commit 71f7f728fd
69 changed files with 863 additions and 864 deletions

View File

@ -9,7 +9,7 @@ export interface HookFilter<TSnapshot> {
*/
export abstract class ExternalStore<TSnapshot> {
#hooks: Array<HookFilter<TSnapshot>> = [];
#snapshot: Readonly<TSnapshot> = {} as Readonly<TSnapshot>;
#snapshot: TSnapshot = {} as TSnapshot;
#changed = true;
hook(fn: HookFn<TSnapshot>) {
@ -35,7 +35,9 @@ export abstract class ExternalStore<TSnapshot> {
protected notifyChange(sn?: TSnapshot) {
this.#changed = true;
if (this.#hooks.length > 0) {
this.#hooks.forEach(h => h.fn(sn));
queueMicrotask(() => {
this.#hooks.forEach(h => h.fn(sn));
});
}
}