mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
chore(infra): remove compatible code (#6833)
This commit is contained in:
@@ -1,48 +1,9 @@
|
||||
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 {
|
||||
legacyChannel = new BroadcastChannel('indexeddb:' + this.workspaceId);
|
||||
senderChannel = new BroadcastChannel('doc:' + this.workspaceId);
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
constructor(private readonly workspaceId: string) {}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user