Skip to content

Commit

Permalink
chore(infra): remove compatible code (toeverything#6833)
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed May 8, 2024
1 parent 87078ff commit 8d8bd49
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 52 deletions.
5 changes: 0 additions & 5 deletions packages/common/infra/src/sync/doc/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ export type DocEvent =
docId: string;
update: Uint8Array;
clientId: string;
}
| {
type: 'LegacyClientUpdateCommitted';
docId: string;
update: Uint8Array;
};

export interface DocEventBus {
Expand Down
7 changes: 0 additions & 7 deletions packages/common/infra/src/sync/doc/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,6 @@ export class DocEngineLocalPart {
});
}
},
LegacyClientUpdateCommitted: ({ docId, update }) => {
this.schedule({
type: 'save',
docId,
update,
});
},
};

handleDocUpdate = (update: Uint8Array, origin: any, doc: YDoc) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down

0 comments on commit 8d8bd49

Please sign in to comment.