mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
chore(infra): remove compatible code (#6833)
This commit is contained in:
@@ -11,11 +11,6 @@ export type DocEvent =
|
|||||||
docId: string;
|
docId: string;
|
||||||
update: Uint8Array;
|
update: Uint8Array;
|
||||||
clientId: string;
|
clientId: string;
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: 'LegacyClientUpdateCommitted';
|
|
||||||
docId: string;
|
|
||||||
update: Uint8Array;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface DocEventBus {
|
export interface DocEventBus {
|
||||||
|
|||||||
@@ -254,13 +254,6 @@ export class DocEngineLocalPart {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
LegacyClientUpdateCommitted: ({ docId, update }) => {
|
|
||||||
this.schedule({
|
|
||||||
type: 'save',
|
|
||||||
docId,
|
|
||||||
update,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDocUpdate = (update: Uint8Array, origin: any, doc: YDoc) => {
|
handleDocUpdate = (update: Uint8Array, origin: any, doc: YDoc) => {
|
||||||
|
|||||||
@@ -1,48 +1,9 @@
|
|||||||
import type { DocEvent, DocEventBus } from '@toeverything/infra';
|
import type { DocEvent, DocEventBus } from '@toeverything/infra';
|
||||||
|
|
||||||
type LegacyChannelMessage = {
|
|
||||||
type: 'db-updated';
|
|
||||||
payload: {
|
|
||||||
docId: string;
|
|
||||||
update: Uint8Array;
|
|
||||||
};
|
|
||||||
__from_new_doc_engine?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export class BroadcastChannelDocEventBus implements DocEventBus {
|
export class BroadcastChannelDocEventBus implements DocEventBus {
|
||||||
legacyChannel = new BroadcastChannel('indexeddb:' + this.workspaceId);
|
|
||||||
senderChannel = new BroadcastChannel('doc:' + this.workspaceId);
|
senderChannel = new BroadcastChannel('doc:' + this.workspaceId);
|
||||||
constructor(private readonly workspaceId: string) {
|
constructor(private readonly workspaceId: string) {}
|
||||||
this.legacyChannel.addEventListener(
|
|
||||||
'message',
|
|
||||||
(event: MessageEvent<LegacyChannelMessage>) => {
|
|
||||||
if (event.data.__from_new_doc_engine) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.data.type === 'db-updated') {
|
|
||||||
this.emit({
|
|
||||||
type: 'LegacyClientUpdateCommitted',
|
|
||||||
docId: event.data.payload.docId,
|
|
||||||
update: event.data.payload.update,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
emit(event: DocEvent): void {
|
emit(event: DocEvent): void {
|
||||||
if (
|
|
||||||
event.type === 'ClientUpdateCommitted' ||
|
|
||||||
event.type === 'ServerUpdateCommitted'
|
|
||||||
) {
|
|
||||||
this.legacyChannel.postMessage({
|
|
||||||
type: 'db-updated',
|
|
||||||
payload: {
|
|
||||||
docId: event.docId,
|
|
||||||
update: event.update,
|
|
||||||
},
|
|
||||||
__from_new_doc_engine: true,
|
|
||||||
} satisfies LegacyChannelMessage);
|
|
||||||
}
|
|
||||||
this.senderChannel.postMessage(event);
|
this.senderChannel.postMessage(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user