mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 05:47:09 +08:00
feat(nbstore): add doc sync state (#9131)
This commit is contained in:
@@ -1,10 +1,21 @@
|
||||
import { combineLatest, map, type Observable, of } from 'rxjs';
|
||||
|
||||
import type { BlobStorage, DocStorage, SpaceStorage } from '../storage';
|
||||
import type { AwarenessStorage } from '../storage/awareness';
|
||||
import { AwarenessSync } from './awareness';
|
||||
import { BlobSync } from './blob';
|
||||
import { DocSync } from './doc';
|
||||
import { DocSync, type DocSyncState } from './doc';
|
||||
|
||||
export interface SyncState {
|
||||
doc?: DocSyncState;
|
||||
}
|
||||
|
||||
export class Sync {
|
||||
private readonly doc: DocSync | null;
|
||||
private readonly blob: BlobSync | null;
|
||||
readonly doc: DocSync | null;
|
||||
readonly blob: BlobSync | null;
|
||||
readonly awareness: AwarenessSync | null;
|
||||
|
||||
readonly state$: Observable<SyncState>;
|
||||
|
||||
constructor(
|
||||
readonly local: SpaceStorage,
|
||||
@@ -13,6 +24,7 @@ export class Sync {
|
||||
const doc = local.tryGet('doc');
|
||||
const blob = local.tryGet('blob');
|
||||
const sync = local.tryGet('sync');
|
||||
const awareness = local.tryGet('awareness');
|
||||
|
||||
this.doc =
|
||||
doc && sync
|
||||
@@ -32,6 +44,18 @@ export class Sync {
|
||||
.filter((v): v is BlobStorage => !!v)
|
||||
)
|
||||
: null;
|
||||
this.awareness = awareness
|
||||
? new AwarenessSync(
|
||||
awareness,
|
||||
peers
|
||||
.map(peer => peer.tryGet('awareness'))
|
||||
.filter((v): v is AwarenessStorage => !!v)
|
||||
)
|
||||
: null;
|
||||
|
||||
this.state$ = combineLatest([this.doc?.state$ ?? of(undefined)]).pipe(
|
||||
map(([doc]) => ({ doc }))
|
||||
);
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
Reference in New Issue
Block a user