From ad04bb78a257103cceb4e193b32de80216d6911a Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Wed, 5 Jul 2023 21:04:54 +0200 Subject: [PATCH] refactor: clean up y-doc sync adapter code Signed-off-by: Tilman Vatteroth --- commons/src/y-doc-sync/y-doc-sync-adapter.ts | 26 +++++++------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/commons/src/y-doc-sync/y-doc-sync-adapter.ts b/commons/src/y-doc-sync/y-doc-sync-adapter.ts index 75d12af72..00de3d8ae 100644 --- a/commons/src/y-doc-sync/y-doc-sync-adapter.ts +++ b/commons/src/y-doc-sync/y-doc-sync-adapter.ts @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: AGPL-3.0-only */ -import { MessageTransporter } from '../message-transporters/message-transporter.js' +import { MessageTransporter } from '../message-transporters/index.js' import { Message, MessageType } from '../message-transporters/message.js' import { RealtimeDoc } from './realtime-doc.js' import { Listener } from 'eventemitter2' @@ -54,10 +54,6 @@ export abstract class YDocSyncAdapter { }) as Listener } - public getMessageTransporter(): MessageTransporter { - return this.messageTransporter - } - public isSynced(): boolean { return this.synced } @@ -71,12 +67,10 @@ export abstract class YDocSyncAdapter { const stateRequestListener = this.messageTransporter.on( MessageType.NOTE_CONTENT_STATE_REQUEST, (payload) => { - if (this.doc) { - this.messageTransporter.sendMessage({ - type: MessageType.NOTE_CONTENT_UPDATE, - payload: this.doc.encodeStateAsUpdate(payload.payload) - }) - } + this.messageTransporter.sendMessage({ + type: MessageType.NOTE_CONTENT_UPDATE, + payload: this.doc.encodeStateAsUpdate(payload.payload) + }) }, { objectify: true } ) as Listener @@ -128,11 +122,9 @@ export abstract class YDocSyncAdapter { } public requestDocumentState(): void { - if (this.doc) { - this.messageTransporter.sendMessage({ - type: MessageType.NOTE_CONTENT_STATE_REQUEST, - payload: this.doc.encodeStateVector() - }) - } + this.messageTransporter.sendMessage({ + type: MessageType.NOTE_CONTENT_STATE_REQUEST, + payload: this.doc.encodeStateVector() + }) } }