Skip to content

Commit

Permalink
refactor(Editor): instantiate api outside sync service
Browse files Browse the repository at this point in the history
Signed-off-by: Max <max@nextcloud.com>
  • Loading branch information
max-nextcloud committed Nov 25, 2024
1 parent a52bc33 commit ea1a4fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ export default {
// });
this.$providers = []
this.$editor = null
this.$api = null
this.$syncService = null
this.$attachmentResolver = null
},
Expand All @@ -379,16 +380,20 @@ export default {
}
const guestName = localStorage.getItem('nick') ? localStorage.getItem('nick') : ''

this.$syncService = new SyncService({
this.$api = new SessionApi({
guestName,
shareToken: this.shareToken,
filePath: this.relativePath,
baseVersionEtag: this.$baseVersionEtag,
forceRecreate: this.forceRecreate,
})

this.$syncService = new SyncService({
baseVersionEtag: this.$baseVersionEtag,
serialize: this.isRichEditor
? (content) => createMarkdownSerializer(this.$editor.schema).serialize(content ?? this.$editor.state.doc)
: (content) => serializePlainText(content ?? this.$editor.state.doc),
getDocumentState: () => getDocumentState(this.$ydoc),
api: this.$api,
})

this.listenSyncServiceEvents()
Expand Down
7 changes: 4 additions & 3 deletions src/services/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import debounce from 'debounce'

import PollingBackend from './PollingBackend.js'
import Outbox from './Outbox.ts'
import SessionApi, { Connection } from './SessionApi.js'
import { Connection } from './SessionApi.js'
import { documentStateToStep } from '../helpers/yjs.js'
import { logger } from '../helpers/logger.js'

Expand Down Expand Up @@ -59,13 +59,13 @@ class SyncService {
#connection
#outbox = new Outbox()

constructor({ baseVersionEtag, serialize, getDocumentState, ...options }) {
constructor({ baseVersionEtag, serialize, getDocumentState, api }) {
/** @type {import('mitt').Emitter<import('./SyncService').EventTypes>} _bus */
this._bus = mitt()

this.serialize = serialize
this.getDocumentState = getDocumentState
this._api = new SessionApi(options)
this._api = api
this.#connection = null

this.stepClientIDs = []
Expand Down Expand Up @@ -124,6 +124,7 @@ class SyncService {
this.baseVersionEtag = this.#connection.document.baseVersionEtag
this.emit('opened', this.connectionState)
this.emit('loaded', this.connectionState)

return this.connectionState
}

Expand Down

0 comments on commit ea1a4fb

Please sign in to comment.