mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-21 09:16:30 -05:00
fix(commons): extract name of markdown content yjs channel into the commons package
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
329a4d4e55
commit
11c2f57e4b
6 changed files with 22 additions and 13 deletions
|
@ -3,7 +3,10 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { encodeDocumentUpdateMessage } from '@hedgedoc/commons';
|
||||
import {
|
||||
encodeDocumentUpdateMessage,
|
||||
MARKDOWN_CONTENT_CHANNEL_NAME,
|
||||
} from '@hedgedoc/commons';
|
||||
import { Doc } from 'yjs';
|
||||
|
||||
import { RealtimeNote } from './realtime-note';
|
||||
|
@ -13,8 +16,6 @@ import { WebsocketConnection } from './websocket-connection';
|
|||
* This is the implementation of {@link Doc YDoc} which includes additional handlers for message sending and receiving.
|
||||
*/
|
||||
export class WebsocketDoc extends Doc {
|
||||
private static readonly channelName = 'markdownContent';
|
||||
|
||||
/**
|
||||
* Creates a new WebsocketDoc instance.
|
||||
*
|
||||
|
@ -55,7 +56,7 @@ export class WebsocketDoc extends Doc {
|
|||
* @private
|
||||
*/
|
||||
private initializeContent(initialContent: string): void {
|
||||
this.getText(WebsocketDoc.channelName).insert(0, initialContent);
|
||||
this.getText(MARKDOWN_CONTENT_CHANNEL_NAME).insert(0, initialContent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,6 +67,6 @@ export class WebsocketDoc extends Doc {
|
|||
* @return The current note content.
|
||||
*/
|
||||
public getCurrentContent(): string {
|
||||
return this.getText(WebsocketDoc.channelName).toString();
|
||||
return this.getText(MARKDOWN_CONTENT_CHANNEL_NAME).toString();
|
||||
}
|
||||
}
|
||||
|
|
7
commons/src/constants/markdown-content-channel-name.ts
Normal file
7
commons/src/constants/markdown-content-channel-name.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
export const MARKDOWN_CONTENT_CHANNEL_NAME = 'markdownContent'
|
|
@ -33,3 +33,5 @@ export {
|
|||
export type { MessageTransporterEvents } from './y-doc-message-transporter.js'
|
||||
|
||||
export { waitForOtherPromisesToFinish } from './utils/wait-for-other-promises-to-finish.js'
|
||||
|
||||
export { MARKDOWN_CONTENT_CHANNEL_NAME } from './constants/markdown-content-channel-name.js'
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { MARKDOWN_CONTENT_CHANNEL_NAME } from './constants/markdown-content-channel-name.js'
|
||||
import { encodeDocumentUpdateMessage } from './messages/document-update-message.js'
|
||||
import { MessageType } from './messages/message-type.enum.js'
|
||||
import { YDocMessageTransporter } from './y-doc-message-transporter.js'
|
||||
|
@ -55,9 +56,9 @@ describe('message transporter', () =>
|
|||
const docClient2: Doc = new Doc()
|
||||
const dummyAwareness: Awareness = new Awareness(docServer)
|
||||
|
||||
const textServer = docServer.getText('markdownContent')
|
||||
const textClient1 = docClient1.getText('markdownContent')
|
||||
const textClient2 = docClient2.getText('markdownContent')
|
||||
const textServer = docServer.getText(MARKDOWN_CONTENT_CHANNEL_NAME)
|
||||
const textClient1 = docClient1.getText(MARKDOWN_CONTENT_CHANNEL_NAME)
|
||||
const textClient2 = docClient2.getText(MARKDOWN_CONTENT_CHANNEL_NAME)
|
||||
textServer.insert(0, 'This is a test note')
|
||||
|
||||
textServer.observe(() =>
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { MARKDOWN_CONTENT_CHANNEL_NAME } from './use-markdown-content-y-text'
|
||||
import { YDocMessageTransporter } from '@hedgedoc/commons'
|
||||
import { MARKDOWN_CONTENT_CHANNEL_NAME, YDocMessageTransporter } from '@hedgedoc/commons'
|
||||
import type { Awareness } from 'y-protocols/awareness'
|
||||
import type { Doc } from 'yjs'
|
||||
|
||||
|
|
|
@ -3,11 +3,10 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { MARKDOWN_CONTENT_CHANNEL_NAME } from '@hedgedoc/commons'
|
||||
import { useMemo } from 'react'
|
||||
import type { Doc } from 'yjs'
|
||||
import type { YText } from 'yjs/dist/src/types/YText'
|
||||
|
||||
export const MARKDOWN_CONTENT_CHANNEL_NAME = 'markdownContent'
|
||||
import type { Text as YText } from 'yjs'
|
||||
|
||||
/**
|
||||
* Extracts the y-text channel that saves the markdown content from the given yDoc.
|
||||
|
|
Loading…
Reference in a new issue