-
Notifications
You must be signed in to change notification settings - Fork 110
Decompose SyncService #7381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Decompose SyncService #7381
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
95764c6
chore(split): SaveService from SyncService
max-nextcloud 2405e75
chore(type): sync service with typescript
max-nextcloud 8525912
chore(migrate): sync service mixin to composable
max-nextcloud 507a7a5
chore(refactor): watch sync service to create save service
max-nextcloud 594fb1a
chore(refactor): move connectSyncService into useSyncService composable
max-nextcloud 725872c
refactor(compose): migrate save service to composable
max-nextcloud 9fdf878
refactor(editor): detect rich editor based on markdown extension
max-nextcloud 94f7619
refactor(editor): always provide an editor
max-nextcloud e8d184a
refactor(cleanup): unwrap connection
max-nextcloud c856f2f
chore(minor): clean up redundant injects
max-nextcloud 00c18c4
chore(refactor): simplify types for props
max-nextcloud c71503e
chore(refactor): watch sync service in useConnection
max-nextcloud 7265f02
chore(extract): Mentions api from extension
max-nextcloud f6b76f3
chore(simplify): SyncService.open returns void
max-nextcloud 90ae016
chore(simplify): combine loaded and opened event
max-nextcloud 8a46d28
chore(cleanup): unused getter
max-nextcloud 798c4b8
fix(menu): call base components setup function
max-nextcloud 8b45a52
chore(refactor): connect from useConnection composable
max-nextcloud 7bc34c9
chore(cleanup): sync and save service are always defined now
max-nextcloud d4a09c4
test(cy): properly close connections
max-nextcloud e6fc63b
chore(refactor): sync service with new connection
max-nextcloud c3230d3
chore(refactor): instantiate SessionConnection with plain data
max-nextcloud 7dc8e25
fix(sync): stop autosave when closing connection
max-nextcloud 7c52d1c
chore(cleanup): ? on attributes that are always truthy
max-nextcloud f370913
chore(cleanup): avoid reuse of isRichEditor name
max-nextcloud 6c76f27
chore(cleanup): remove outdated comment
max-nextcloud 9ea9857
chore(copyright): fix year to 2025
max-nextcloud File filter
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(split): SaveService from SyncService
Signed-off-by: Max <[email protected]>
- Loading branch information
commit 95764c68e3d9a33a37d090fa16a3c85e741f0d49
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| /* eslint-disable jsdoc/valid-types */ | ||
|
|
||
| import debounce from 'debounce' | ||
|
|
||
| import { logger } from '../helpers/logger.js' | ||
|
|
||
| /** | ||
| * Interval to save the serialized document and the document state | ||
| * | ||
| * @type {number} time in ms | ||
| */ | ||
| const AUTOSAVE_INTERVAL = 30000 | ||
|
|
||
| class SaveService { | ||
| syncService | ||
| serialize | ||
| getDocumentState | ||
|
|
||
| constructor({ syncService, serialize, getDocumentState }) { | ||
| this.syncService = syncService | ||
| this.serialize = serialize | ||
| this.getDocumentState = getDocumentState | ||
| this.autosave = debounce(this._autosave.bind(this), AUTOSAVE_INTERVAL) | ||
| } | ||
|
|
||
| get connection() { | ||
| return this.syncService.connection | ||
| } | ||
|
|
||
| get emit() { | ||
| return this.syncService.emit.bind(this.syncService) | ||
| } | ||
|
|
||
| get hasActiveConnection() { | ||
| return this.connection && !this.connection.isClosed | ||
| } | ||
|
|
||
| _getContent() { | ||
| return this.serialize() | ||
| } | ||
|
|
||
| async save({ force = false, manualSave = true } = {}) { | ||
| logger.debug('[SaveService] saving', arguments[0]) | ||
| try { | ||
| const response = await this.connection.save({ | ||
| version: this.version, | ||
| autosaveContent: this._getContent(), | ||
| documentState: this.getDocumentState(), | ||
| force, | ||
| manualSave, | ||
| }) | ||
| this.emit('stateChange', { dirty: false }) | ||
| this.connection.document.lastSavedVersionTime = Date.now() / 1000 | ||
| logger.debug('[SaveService] saved', response) | ||
| const { document, sessions } = response.data | ||
| this.emit('save', { document, sessions }) | ||
| this.autosave.clear() | ||
| } catch (e) { | ||
| logger.error('Failed to save document.', { error: e }) | ||
| throw e | ||
| } | ||
| } | ||
|
|
||
| saveViaSendBeacon() { | ||
| this.connection.saveViaSendBeacon({ | ||
| version: this.version, | ||
| autosaveContent: this._getContent(), | ||
| documentState: this.getDocumentState(), | ||
| force: false, | ||
| manualSave: true, | ||
| }) | ||
| logger.debug('[SaveService] saved using sendBeacon') | ||
| } | ||
|
|
||
| forceSave() { | ||
| return this.save({ force: true }) | ||
| } | ||
|
|
||
| _autosave() { | ||
| return this.save({ manualSave: false }).catch((error) => { | ||
| logger.error('Failed to autosave document.', { error }) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| export { SaveService } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.