Skip to content

Commit

Permalink
feat(ui-store): add done callback for BaseStore all method
Browse files Browse the repository at this point in the history
release-as: 0.8.0
  • Loading branch information
zzcwoshizz committed Jan 12, 2023
1 parent b0b6357 commit f22d72c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
4 changes: 1 addition & 3 deletions packages/ui-did-keyring/src/KiltDid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export class KiltDid extends KiltDidSuper {

jsons.forEach((json) => this.keyring.addFromJson(json));
dids.forEach((did) => super.addDid(did));

resolve();
});
}, resolve);
});
}

Expand Down
4 changes: 1 addition & 3 deletions packages/ui-did-keyring/src/ZkDid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export class ZkDid extends ZkDidSuper {

this.dids.set(did.id, did);
});

resolve();
});
}, resolve);
});
}

Expand Down
8 changes: 4 additions & 4 deletions packages/ui-store/src/BaseStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import { Events } from './event/Event';

export abstract class BaseStore extends Events {
abstract all(fn: (key: string, value: unknown) => void): void;
abstract get(key: string, fn: (value: unknown) => void): void;
abstract set(key: string, value: unknown, fn?: () => void): void;
abstract remove(key: string, fn?: () => void): void;
public abstract all(fn: (key: string, value: unknown) => void, done?: () => void): void;
public abstract get(key: string, fn: (value: unknown) => void): void;
public abstract set(key: string, value: unknown, fn?: () => void): void;
public abstract remove(key: string, fn?: () => void): void;
}
3 changes: 2 additions & 1 deletion packages/ui-store/src/BrowserSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export class BrowserSession extends BaseStore {
this.#session = new SessionStorage();
}

public all(fn: (key: string, value: unknown) => void): void {
public all(fn: (key: string, value: unknown) => void, done?: () => void): void {
this.#session.each((key: string, value: unknown): void => {
fn(key, value);
});
done?.();
}

public get(key: string, fn: (value: unknown) => void): void {
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-store/src/BrowserStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export class BrowserStore extends BaseStore {
});
}

public all(fn: (key: string, value: unknown) => void): void {
public all(fn: (key: string, value: unknown) => void, done?: () => void): void {
this.#store.each((key: string, value: unknown): void => {
fn(key, value);
});
done?.();
}

public get(key: string, fn: (value: unknown) => void): void {
Expand Down
4 changes: 3 additions & 1 deletion packages/ui-store/src/ExtensionSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ export class ExtensionSession extends BaseStore {
});
}

public all(fn: (key: string, value: string) => void) {
public all(fn: (key: string, value: string) => void, done?: () => void) {
session.get(null, (items) => {
for (const key in items) {
fn(key, items[key]);
}

done?.();
});
}

Expand Down
4 changes: 3 additions & 1 deletion packages/ui-store/src/ExtensionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ export class ExtensionStore extends BaseStore {
});
}

public all(fn: (key: string, value: string) => void) {
public all(fn: (key: string, value: string) => void, done?: () => void) {
storage.get(null, (items) => {
for (const key in items) {
fn(key, items[key]);
}

done?.();
});
}

Expand Down

0 comments on commit f22d72c

Please sign in to comment.