mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 13:57:02 +08:00
feat(nbstore): improve nbstore (#9512)
This commit is contained in:
@@ -2,6 +2,7 @@ import type {
|
||||
AwarenessRecord,
|
||||
AwarenessStorage,
|
||||
} from '../../storage/awareness';
|
||||
import type { PeerStorageOptions } from '../types';
|
||||
|
||||
export interface AwarenessSync {
|
||||
update(record: AwarenessRecord, origin?: string): Promise<void>;
|
||||
@@ -13,14 +14,13 @@ export interface AwarenessSync {
|
||||
}
|
||||
|
||||
export class AwarenessSyncImpl implements AwarenessSync {
|
||||
constructor(
|
||||
readonly local: AwarenessStorage,
|
||||
readonly remotes: AwarenessStorage[]
|
||||
) {}
|
||||
constructor(readonly storages: PeerStorageOptions<AwarenessStorage>) {}
|
||||
|
||||
async update(record: AwarenessRecord, origin?: string) {
|
||||
await Promise.all(
|
||||
[this.local, ...this.remotes].map(peer => peer.update(record, origin))
|
||||
[this.storages.local, ...Object.values(this.storages.remotes)].map(peer =>
|
||||
peer.update(record, origin)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -29,9 +29,10 @@ export class AwarenessSyncImpl implements AwarenessSync {
|
||||
onUpdate: (update: AwarenessRecord, origin?: string) => void,
|
||||
onCollect: () => Promise<AwarenessRecord | null>
|
||||
): () => void {
|
||||
const unsubscribes = [this.local, ...this.remotes].map(peer =>
|
||||
peer.subscribeUpdate(id, onUpdate, onCollect)
|
||||
);
|
||||
const unsubscribes = [
|
||||
this.storages.local,
|
||||
...Object.values(this.storages.remotes),
|
||||
].map(peer => peer.subscribeUpdate(id, onUpdate, onCollect));
|
||||
return () => {
|
||||
unsubscribes.forEach(unsubscribe => unsubscribe());
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user