Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore(type): sync service bus and events
Remove the delegations to only use the typed interface.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Oct 12, 2025
commit 5d03e24504ca717455b7ed5794baf67f605c0edd
2 changes: 1 addition & 1 deletion cypress/e2e/api/SyncServiceProvider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { randUser } from '../../utils/index.js'
import SessionApi from '../../../src/services/SessionApi.js'
import { SyncService } from '../../../src/services/SyncService.js'
import { SyncService } from '../../../src/services/SyncService.ts'
import createSyncServiceProvider from '../../../src/services/SyncServiceProvider.js'
import { Doc } from 'yjs'

Expand Down
38 changes: 19 additions & 19 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ import ReadonlyBar from './Menu/ReadonlyBar.vue'

import { logger } from '../helpers/logger.js'
import { getDocumentState } from '../helpers/yjs.js'
import { SyncService, ERROR_TYPE, IDLE_TIMEOUT } from './../services/SyncService.js'
import { SyncService, ERROR_TYPE, IDLE_TIMEOUT } from './../services/SyncService.ts'
import SessionApi from '../services/SessionApi.js'
import createSyncServiceProvider from './../services/SyncServiceProvider.js'
import AttachmentResolver from './../services/AttachmentResolver.js'
Expand Down Expand Up @@ -462,27 +462,27 @@ export default {
},

listenSyncServiceEvents() {
this.$syncService
.on('opened', this.onOpened)
.on('change', this.onChange)
.on('loaded', this.onLoaded)
.on('sync', this.onSync)
.on('error', this.onError)
.on('stateChange', this.onStateChange)
.on('idle', this.onIdle)
.on('save', this.onSave)
const bus = this.$syncService.bus
bus.on('opened', this.onOpened)
bus.on('change', this.onChange)
bus.on('loaded', this.onLoaded)
bus.on('sync', this.onSync)
bus.on('error', this.onError)
bus.on('stateChange', this.onStateChange)
bus.on('idle', this.onIdle)
bus.on('save', this.onSave)
},

unlistenSyncServiceEvents() {
this.$syncService
.off('opened', this.onOpened)
.off('change', this.onChange)
.off('loaded', this.onLoaded)
.off('sync', this.onSync)
.off('error', this.onError)
.off('stateChange', this.onStateChange)
.off('idle', this.onIdle)
.off('save', this.onSave)
const bus = this.$syncService.bus
bus.off('opened', this.onOpened)
bus.off('change', this.onChange)
bus.off('loaded', this.onLoaded)
bus.off('sync', this.onSync)
bus.off('error', this.onError)
bus.off('stateChange', this.onStateChange)
bus.off('idle', this.onIdle)
bus.off('save', this.onSave)
},

reconnect() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor/DocumentStatus/SyncStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<script>

import { ERROR_TYPE } from '../../../services/SyncService.js'
import { ERROR_TYPE } from '../../../services/SyncService.ts'
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'

export default {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor/SessionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwit
import NcPopover from '@nextcloud/vue/components/NcPopover'
import AccountMultipleIcon from 'vue-material-design-icons/AccountMultiple.vue'
import AvatarWrapper from './AvatarWrapper.vue'
import { COLLABORATOR_DISCONNECT_TIME, COLLABORATOR_IDLE_TIME } from '../../services/SyncService.js'
import { COLLABORATOR_DISCONNECT_TIME, COLLABORATOR_IDLE_TIME } from '../../services/SyncService.ts'
import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor/Status.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<script>

import { ERROR_TYPE } from '../../services/SyncService.js'
import { ERROR_TYPE } from '../../services/SyncService.ts'
import moment from '@nextcloud/moment'
import NcButton from '@nextcloud/vue/components/NcButton'
import NcSavingIndicatorIcon from '@nextcloud/vue/components/NcSavingIndicatorIcon'
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ let FilesHeaderRichWorkspaceView
let FilesHeaderRichWorkspaceInstance
let latestFolder

function enabled(_, view) {
const enabled = (_, view) => {
return ['files', 'favorites', 'public-share'].includes(view.id)
}

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/yjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function applyDocumentState(ydoc, documentState, origin) {
* and encode it and wrap it in a step data structure.
*
* @param {string} documentState - base64 encoded doc state
* @return {string} base64 encoded yjs sync protocol update message
* @return {{ step: string }} base64 encoded yjs sync protocol update message
*/
export function documentStateToStep(documentState) {
const message = documentStateToUpdateMessage(documentState)
Expand Down
18 changes: 9 additions & 9 deletions src/services/PollingBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { logger } from '../helpers/logger.js'
import { SyncService, ERROR_TYPE } from './SyncService.js'
import { SyncService, ERROR_TYPE } from './SyncService.ts'
import { Connection } from './SessionApi.js'
import getNotifyBus from './NotifyService.js'

Expand Down Expand Up @@ -126,7 +126,7 @@ class PollingBackend {
const { document, sessions } = data
this.#fetchRetryCounter = 0

this.#syncService.emit('change', { document, sessions })
this.#syncService.bus.emit('change', { document, sessions })
this.#syncService.receiveSteps(data)

if (data.steps.length === 0) {
Expand All @@ -145,7 +145,7 @@ class PollingBackend {
} else {
this.increaseRefetchTimer()
}
this.#syncService.emit('stateChange', { initialLoading: true })
this.#syncService.bus.emit('stateChange', { initialLoading: true })
return
}

Expand All @@ -158,7 +158,7 @@ class PollingBackend {
if (!e.response || e.code === 'ECONNABORTED') {
if (this.#fetchRetryCounter++ >= MAX_RETRY_FETCH_COUNT) {
logger.error('[PollingBackend:fetchSteps] Network error when fetching steps, emitting CONNECTION_FAILED')
this.#syncService.emit('error', { type: ERROR_TYPE.CONNECTION_FAILED, data: {} })
this.#syncService.bus.emit('error', { type: ERROR_TYPE.CONNECTION_FAILED, data: {} })

} else {
logger.error(`[PollingBackend:fetchSteps] Network error when fetching steps, retry ${this.#fetchRetryCounter}`)
Expand All @@ -167,25 +167,25 @@ class PollingBackend {
// Still apply the steps to update our version of the document
this._handleResponse(e.response)
logger.error('Conflict during file save, please resolve')
this.#syncService.emit('error', {
this.#syncService.bus.emit('error', {
type: ERROR_TYPE.SAVE_COLLISSION,
data: {
outsideChange: e.response.data.outsideChange,
},
})
} else if (e.response.status === 412) {
this.#syncService.emit('error', { type: ERROR_TYPE.LOAD_ERROR, data: e.response })
this.#syncService.bus.emit('error', { type: ERROR_TYPE.LOAD_ERROR, data: e.response })
this.disconnect()
} else if ([403, 404].includes(e.response.status)) {
this.#syncService.emit('error', { type: ERROR_TYPE.SOURCE_NOT_FOUND, data: {} })
this.#syncService.bus.emit('error', { type: ERROR_TYPE.SOURCE_NOT_FOUND, data: {} })
this.disconnect()
} else if ([502, 503].includes(e.response.status)) {
this.increaseRefetchTimer()
this.#syncService.emit('error', { type: ERROR_TYPE.CONNECTION_FAILED, data: {} })
this.#syncService.bus.emit('error', { type: ERROR_TYPE.CONNECTION_FAILED, data: {} })
logger.error('Failed to fetch steps due to unavailable service', { error: e })
} else {
this.disconnect()
this.#syncService.emit('error', { type: ERROR_TYPE.CONNECTION_FAILED, data: {} })
this.#syncService.bus.emit('error', { type: ERROR_TYPE.CONNECTION_FAILED, data: {} })
logger.error('Failed to fetch steps due to other reason', { error: e })
}

Expand Down
31 changes: 0 additions & 31 deletions src/services/SyncService.d.ts

This file was deleted.

Loading