mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-22 15:41:36 +00:00
refactor: clean up y-doc sync adapter code
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
25ee20c15d
commit
ad04bb78a2
1 changed files with 9 additions and 17 deletions
|
@ -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()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue