mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 06:18:45 +08:00
style: enable rxjs/finnish (#6276)
chore(infra): use finnish notation for observables do rename
This commit is contained in:
@@ -14,13 +14,13 @@ describe('Workspace System', () => {
|
||||
const provider = services.provider();
|
||||
const workspaceManager = provider.get(WorkspaceManager);
|
||||
const workspaceListService = provider.get(WorkspaceListService);
|
||||
expect(workspaceListService.workspaceList.value.length).toBe(0);
|
||||
expect(workspaceListService.workspaceList$.value.length).toBe(0);
|
||||
|
||||
const { workspace } = workspaceManager.open(
|
||||
await workspaceManager.createWorkspace(WorkspaceFlavour.LOCAL)
|
||||
);
|
||||
|
||||
expect(workspaceListService.workspaceList.value.length).toBe(1);
|
||||
expect(workspaceListService.workspaceList$.value.length).toBe(1);
|
||||
|
||||
const page = workspace.docCollection.createDoc({
|
||||
id: 'page0',
|
||||
|
||||
@@ -32,10 +32,10 @@ export class DocEngine {
|
||||
|
||||
storage: DocStorageInner;
|
||||
|
||||
engineState = LiveData.computed(get => {
|
||||
const localState = get(this.localPart.engineState);
|
||||
engineState$ = LiveData.computed(get => {
|
||||
const localState = get(this.localPart.engineState$);
|
||||
if (this.remotePart) {
|
||||
const remoteState = get(this.remotePart?.engineState);
|
||||
const remoteState = get(this.remotePart?.engineState$);
|
||||
return {
|
||||
total: remoteState.total,
|
||||
syncing: remoteState.syncing,
|
||||
@@ -53,12 +53,12 @@ export class DocEngine {
|
||||
};
|
||||
});
|
||||
|
||||
docState(docId: string) {
|
||||
const localState = this.localPart.docState(docId);
|
||||
const remoteState = this.remotePart?.docState(docId);
|
||||
docState$(docId: string) {
|
||||
const localState$ = this.localPart.docState$(docId);
|
||||
const remoteState$ = this.remotePart?.docState$(docId);
|
||||
return LiveData.computed(get => {
|
||||
const local = get(localState);
|
||||
const remote = remoteState ? get(remoteState) : null;
|
||||
const local = get(localState$);
|
||||
const remote = remoteState$ ? get(remoteState$) : null;
|
||||
return {
|
||||
ready: local.ready,
|
||||
saving: local.syncing,
|
||||
@@ -134,7 +134,7 @@ export class DocEngine {
|
||||
*/
|
||||
waitForSaved() {
|
||||
return new Promise<void>(resolve => {
|
||||
this.engineState
|
||||
this.engineState$
|
||||
.pipe(map(state => state.saving === 0))
|
||||
.subscribe(saved => {
|
||||
if (saved) {
|
||||
@@ -150,7 +150,7 @@ export class DocEngine {
|
||||
*/
|
||||
waitForSynced() {
|
||||
return new Promise<void>(resolve => {
|
||||
this.engineState
|
||||
this.engineState$
|
||||
.pipe(map(state => state.syncing === 0 && state.saving === 0))
|
||||
.subscribe(synced => {
|
||||
if (synced) {
|
||||
@@ -175,7 +175,7 @@ export class DocEngine {
|
||||
*/
|
||||
waitForReady(docId: string) {
|
||||
return new Promise<void>(resolve => {
|
||||
this.docState(docId)
|
||||
this.docState$(docId)
|
||||
.pipe(map(state => state.ready))
|
||||
.subscribe(ready => {
|
||||
if (ready) {
|
||||
|
||||
@@ -48,7 +48,7 @@ export interface LocalDocState {
|
||||
*/
|
||||
export class DocEngineLocalPart {
|
||||
private readonly prioritySettings = new Map<string, number>();
|
||||
private readonly statusUpdatedSubject = new Subject<string>();
|
||||
private readonly statusUpdatedSubject$ = new Subject<string>();
|
||||
|
||||
private readonly status = {
|
||||
docs: new Map<string, YDoc>(),
|
||||
@@ -59,7 +59,7 @@ export class DocEngineLocalPart {
|
||||
currentJob: null as { docId: string; jobs: Job[] } | null,
|
||||
};
|
||||
|
||||
engineState = LiveData.from<LocalEngineState>(
|
||||
engineState$ = LiveData.from<LocalEngineState>(
|
||||
new Observable(subscribe => {
|
||||
const next = () => {
|
||||
subscribe.next({
|
||||
@@ -68,14 +68,14 @@ export class DocEngineLocalPart {
|
||||
});
|
||||
};
|
||||
next();
|
||||
return this.statusUpdatedSubject.subscribe(() => {
|
||||
return this.statusUpdatedSubject$.subscribe(() => {
|
||||
next();
|
||||
});
|
||||
}),
|
||||
{ syncing: 0, total: 0 }
|
||||
);
|
||||
|
||||
docState(docId: string) {
|
||||
docState$(docId: string) {
|
||||
return LiveData.from<LocalDocState>(
|
||||
new Observable(subscribe => {
|
||||
const next = () => {
|
||||
@@ -87,7 +87,7 @@ export class DocEngineLocalPart {
|
||||
});
|
||||
};
|
||||
next();
|
||||
return this.statusUpdatedSubject.subscribe(updatedId => {
|
||||
return this.statusUpdatedSubject$.subscribe(updatedId => {
|
||||
if (updatedId === docId) next();
|
||||
});
|
||||
}),
|
||||
@@ -120,7 +120,7 @@ export class DocEngineLocalPart {
|
||||
}
|
||||
|
||||
this.status.currentJob = { docId, jobs };
|
||||
this.statusUpdatedSubject.next(docId);
|
||||
this.statusUpdatedSubject$.next(docId);
|
||||
|
||||
const { apply, load, save } = groupBy(jobs, job => job.type) as {
|
||||
[key in Job['type']]?: Job[];
|
||||
@@ -139,7 +139,7 @@ export class DocEngineLocalPart {
|
||||
}
|
||||
|
||||
this.status.currentJob = null;
|
||||
this.statusUpdatedSubject.next(docId);
|
||||
this.statusUpdatedSubject$.next(docId);
|
||||
}
|
||||
} finally {
|
||||
dispose();
|
||||
@@ -161,7 +161,7 @@ export class DocEngineLocalPart {
|
||||
});
|
||||
|
||||
this.status.docs.set(doc.guid, doc);
|
||||
this.statusUpdatedSubject.next(doc.guid);
|
||||
this.statusUpdatedSubject$.next(doc.guid);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -186,7 +186,7 @@ export class DocEngineLocalPart {
|
||||
doc.on('update', this.handleDocUpdate);
|
||||
|
||||
this.status.connectedDocs.add(job.docId);
|
||||
this.statusUpdatedSubject.next(job.docId);
|
||||
this.statusUpdatedSubject$.next(job.docId);
|
||||
|
||||
const docData = await this.storage.loadDocFromLocal(job.docId, signal);
|
||||
|
||||
@@ -196,7 +196,7 @@ export class DocEngineLocalPart {
|
||||
|
||||
this.applyUpdate(job.docId, docData);
|
||||
this.status.readyDocs.add(job.docId);
|
||||
this.statusUpdatedSubject.next(job.docId);
|
||||
this.statusUpdatedSubject$.next(job.docId);
|
||||
},
|
||||
save: async (
|
||||
docId: string,
|
||||
@@ -292,7 +292,7 @@ export class DocEngineLocalPart {
|
||||
const existingJobs = this.status.jobMap.get(job.docId) ?? [];
|
||||
existingJobs.push(job);
|
||||
this.status.jobMap.set(job.docId, existingJobs);
|
||||
this.statusUpdatedSubject.next(job.docId);
|
||||
this.statusUpdatedSubject$.next(job.docId);
|
||||
}
|
||||
|
||||
setPriority(docId: string, priority: number) {
|
||||
|
||||
@@ -81,9 +81,9 @@ export class DocEngineRemotePart {
|
||||
retrying: false,
|
||||
errorMessage: null,
|
||||
};
|
||||
private readonly statusUpdatedSubject = new Subject<string | true>();
|
||||
private readonly statusUpdatedSubject$ = new Subject<string | true>();
|
||||
|
||||
engineState = LiveData.from<RemoteEngineState>(
|
||||
engineState$ = LiveData.from<RemoteEngineState>(
|
||||
new Observable(subscribe => {
|
||||
const next = () => {
|
||||
if (!this.status.syncing) {
|
||||
@@ -103,7 +103,7 @@ export class DocEngineRemotePart {
|
||||
});
|
||||
};
|
||||
next();
|
||||
return this.statusUpdatedSubject.subscribe(() => {
|
||||
return this.statusUpdatedSubject$.subscribe(() => {
|
||||
next();
|
||||
});
|
||||
}),
|
||||
@@ -115,7 +115,7 @@ export class DocEngineRemotePart {
|
||||
}
|
||||
);
|
||||
|
||||
docState(docId: string) {
|
||||
docState$(docId: string) {
|
||||
return LiveData.from<RemoteDocState>(
|
||||
new Observable(subscribe => {
|
||||
const next = () => {
|
||||
@@ -126,7 +126,7 @@ export class DocEngineRemotePart {
|
||||
});
|
||||
};
|
||||
next();
|
||||
return this.statusUpdatedSubject.subscribe(updatedId => {
|
||||
return this.statusUpdatedSubject$.subscribe(updatedId => {
|
||||
if (updatedId === true || updatedId === docId) next();
|
||||
});
|
||||
}),
|
||||
@@ -152,7 +152,7 @@ export class DocEngineRemotePart {
|
||||
}
|
||||
|
||||
this.status.connectedDocs.add(docId);
|
||||
this.statusUpdatedSubject.next(docId);
|
||||
this.statusUpdatedSubject$.next(docId);
|
||||
},
|
||||
push: async (
|
||||
docId: string,
|
||||
@@ -321,7 +321,7 @@ export class DocEngineRemotePart {
|
||||
addDoc: (docId: string) => {
|
||||
if (!this.status.docs.has(docId)) {
|
||||
this.status.docs.add(docId);
|
||||
this.statusUpdatedSubject.next(docId);
|
||||
this.statusUpdatedSubject$.next(docId);
|
||||
this.schedule({
|
||||
type: 'connect',
|
||||
docId,
|
||||
@@ -359,7 +359,7 @@ export class DocEngineRemotePart {
|
||||
logger.error('Remote sync error, retry in 5s', err);
|
||||
this.status.errorMessage =
|
||||
err instanceof Error ? err.message : `${err}`;
|
||||
this.statusUpdatedSubject.next(true);
|
||||
this.statusUpdatedSubject$.next(true);
|
||||
} finally {
|
||||
this.status = {
|
||||
docs: this.status.docs,
|
||||
@@ -371,7 +371,7 @@ export class DocEngineRemotePart {
|
||||
retrying: true,
|
||||
errorMessage: this.status.errorMessage,
|
||||
};
|
||||
this.statusUpdatedSubject.next(true);
|
||||
this.statusUpdatedSubject$.next(true);
|
||||
}
|
||||
await Promise.race([
|
||||
new Promise<void>(resolve => {
|
||||
@@ -420,7 +420,7 @@ export class DocEngineRemotePart {
|
||||
|
||||
logger.info('Remote sync started');
|
||||
this.status.syncing = true;
|
||||
this.statusUpdatedSubject.next(true);
|
||||
this.statusUpdatedSubject$.next(true);
|
||||
|
||||
this.server.onInterrupted(reason => {
|
||||
abort.abort(reason);
|
||||
@@ -471,7 +471,7 @@ export class DocEngineRemotePart {
|
||||
const jobs = this.status.jobMap.get(docId);
|
||||
if (!jobs || jobs.length === 0) {
|
||||
this.status.jobMap.delete(docId);
|
||||
this.statusUpdatedSubject.next(docId);
|
||||
this.statusUpdatedSubject$.next(docId);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ export class DocEngineRemotePart {
|
||||
const existingJobs = this.status.jobMap.get(job.docId) ?? [];
|
||||
existingJobs.push(job);
|
||||
this.status.jobMap.set(job.docId, existingJobs);
|
||||
this.statusUpdatedSubject.next(job.docId);
|
||||
this.statusUpdatedSubject$.next(job.docId);
|
||||
}
|
||||
|
||||
setPriority(docId: string, priority: number) {
|
||||
|
||||
@@ -52,7 +52,7 @@ export class WorkspaceEngine {
|
||||
}
|
||||
|
||||
canGracefulStop() {
|
||||
return this.doc.engineState.value.saving === 0;
|
||||
return this.doc.engineState$.value.saving === 0;
|
||||
}
|
||||
|
||||
async waitForGracefulStop(abort?: AbortSignal) {
|
||||
@@ -67,9 +67,9 @@ export class WorkspaceEngine {
|
||||
this.blob.stop();
|
||||
}
|
||||
|
||||
docEngineState = this.doc.engineState;
|
||||
docEngineState$ = this.doc.engineState$;
|
||||
|
||||
rootDocState = this.doc.docState(this.yDoc.guid);
|
||||
rootDocState$ = this.doc.docState$(this.yDoc.guid);
|
||||
|
||||
waitForSynced() {
|
||||
return this.doc.waitForSynced();
|
||||
|
||||
@@ -86,18 +86,18 @@ export class WorkspaceListService {
|
||||
WorkspaceInformation
|
||||
>();
|
||||
|
||||
status = new LiveData<WorkspaceListStatus>({
|
||||
status$ = new LiveData<WorkspaceListStatus>({
|
||||
loading: true,
|
||||
workspaceList: [],
|
||||
});
|
||||
|
||||
setStatus(status: WorkspaceListStatus) {
|
||||
this.status.next(status);
|
||||
this.status$.next(status);
|
||||
// update cache
|
||||
writeWorkspaceListCache(this.cache, status.workspaceList);
|
||||
}
|
||||
|
||||
workspaceList = this.status.map(x => x.workspaceList);
|
||||
workspaceList$ = this.status$.map(x => x.workspaceList);
|
||||
|
||||
constructor(
|
||||
private readonly providers: WorkspaceListProvider[],
|
||||
@@ -106,8 +106,8 @@ export class WorkspaceListService {
|
||||
// initialize workspace list from cache
|
||||
const cached = readWorkspaceListCache(cache);
|
||||
const workspaceList = cached;
|
||||
this.status.next({
|
||||
...this.status.value,
|
||||
this.status$.next({
|
||||
...this.status$.value,
|
||||
workspaceList,
|
||||
});
|
||||
|
||||
@@ -134,7 +134,7 @@ export class WorkspaceListService {
|
||||
}
|
||||
const metadata = await provider.create(initial);
|
||||
// update workspace list
|
||||
this.setStatus(this.addWorkspace(this.status.value, metadata));
|
||||
this.setStatus(this.addWorkspace(this.status$.value, metadata));
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ export class WorkspaceListService {
|
||||
await provider.delete(workspaceMetadata.id);
|
||||
|
||||
// delete workspace from list
|
||||
this.setStatus(this.deleteWorkspace(this.status.value, workspaceMetadata));
|
||||
this.setStatus(this.deleteWorkspace(this.status$.value, workspaceMetadata));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,7 +201,7 @@ export class WorkspaceListService {
|
||||
added?: WorkspaceMetadata[];
|
||||
deleted?: WorkspaceMetadata[];
|
||||
}) {
|
||||
let status = this.status.value;
|
||||
let status = this.status$.value;
|
||||
|
||||
for (const added of changed.added ?? []) {
|
||||
status = this.addWorkspace(status, added);
|
||||
@@ -239,7 +239,7 @@ export class WorkspaceListService {
|
||||
})
|
||||
.finally(() => {
|
||||
this.setStatus({
|
||||
...this.status.value,
|
||||
...this.status$.value,
|
||||
loading: false,
|
||||
});
|
||||
});
|
||||
@@ -250,7 +250,7 @@ export class WorkspaceListService {
|
||||
this.providers.map(async provider => {
|
||||
try {
|
||||
const list = await provider.getList();
|
||||
const oldList = this.workspaceList.value.filter(
|
||||
const oldList = this.workspaceList$.value.filter(
|
||||
w => w.flavour === provider.name
|
||||
);
|
||||
this.handleWorkspaceChange({
|
||||
|
||||
Reference in New Issue
Block a user