mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-21 17:26:29 -05: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
|
* 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 { Message, MessageType } from '../message-transporters/message.js'
|
||||||
import { RealtimeDoc } from './realtime-doc.js'
|
import { RealtimeDoc } from './realtime-doc.js'
|
||||||
import { Listener } from 'eventemitter2'
|
import { Listener } from 'eventemitter2'
|
||||||
|
@ -54,10 +54,6 @@ export abstract class YDocSyncAdapter {
|
||||||
}) as Listener
|
}) as Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
public getMessageTransporter(): MessageTransporter {
|
|
||||||
return this.messageTransporter
|
|
||||||
}
|
|
||||||
|
|
||||||
public isSynced(): boolean {
|
public isSynced(): boolean {
|
||||||
return this.synced
|
return this.synced
|
||||||
}
|
}
|
||||||
|
@ -71,12 +67,10 @@ export abstract class YDocSyncAdapter {
|
||||||
const stateRequestListener = this.messageTransporter.on(
|
const stateRequestListener = this.messageTransporter.on(
|
||||||
MessageType.NOTE_CONTENT_STATE_REQUEST,
|
MessageType.NOTE_CONTENT_STATE_REQUEST,
|
||||||
(payload) => {
|
(payload) => {
|
||||||
if (this.doc) {
|
this.messageTransporter.sendMessage({
|
||||||
this.messageTransporter.sendMessage({
|
type: MessageType.NOTE_CONTENT_UPDATE,
|
||||||
type: MessageType.NOTE_CONTENT_UPDATE,
|
payload: this.doc.encodeStateAsUpdate(payload.payload)
|
||||||
payload: this.doc.encodeStateAsUpdate(payload.payload)
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{ objectify: true }
|
{ objectify: true }
|
||||||
) as Listener
|
) as Listener
|
||||||
|
@ -128,11 +122,9 @@ export abstract class YDocSyncAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public requestDocumentState(): void {
|
public requestDocumentState(): void {
|
||||||
if (this.doc) {
|
this.messageTransporter.sendMessage({
|
||||||
this.messageTransporter.sendMessage({
|
type: MessageType.NOTE_CONTENT_STATE_REQUEST,
|
||||||
type: MessageType.NOTE_CONTENT_STATE_REQUEST,
|
payload: this.doc.encodeStateVector()
|
||||||
payload: this.doc.encodeStateVector()
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue