Skip to content

Commit d0f0281

Browse files
committed
Decouple sync from docs load event
1 parent 3e1991c commit d0f0281

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

app.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { appEventTypes, logEvent } from '/helpers/app'
33
import { loadKeybindings } from '/src/store/modules/keybindings'
44
import { loadDocs } from '/src/store/plugins/caching/documents'
55
import { loadSettings } from '/src/store/plugins/caching/settings'
6+
import { syncDocs } from '/src/store/plugins/sync'
67
78
import 'overlayscrollbars/overlayscrollbars.css'
89
@@ -21,6 +22,8 @@ export default defineComponent({
2122
await loadDocs(store)
2223
await loadKeybindings(store)
2324
25+
syncDocs(store)
26+
2427
// This is used by tests to determine when the app is ready.
2528
document.body.dataset.isMounted = 'true'
2629

src/store/plugins/sync.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { type Plugin } from 'vuex'
1+
import { type Plugin, type Store } from 'vuex'
22
import { debouncer } from '/src/common/debouncer'
33

44
import {
55
ADD_DOCUMENT,
66
DISCARD_DOCUMENT,
7-
DOCUMENTS_LOADED,
87
EDIT_DOCUMENT,
98
RESTORE_DOCUMENT,
109
RESTRICT_DOCUMENT,
@@ -23,20 +22,14 @@ const syncPlugin: Plugin<any> = (store) => {
2322
switch (type) {
2423
case ADD_DOCUMENT:
2524
case DISCARD_DOCUMENT:
26-
case DOCUMENTS_LOADED:
2725
case EDIT_DOCUMENT:
2826
case RESTORE_DOCUMENT:
2927
case RESTRICT_DOCUMENT:
3028
case SET_ONLINE:
3129
case SET_USER:
3230
case SHARE_DOCUMENT:
3331
case TOUCH_DOCUMENT:
34-
// sync documents if online
35-
if (store.state.online && store.state.auth.user) {
36-
debounce('sync', () => {
37-
store.dispatch(SYNC)
38-
})
39-
}
32+
syncDocs(store)
4033

4134
break
4235
default:
@@ -45,4 +38,13 @@ const syncPlugin: Plugin<any> = (store) => {
4538
})
4639
}
4740

41+
export const syncDocs = (store: Store<any>) => {
42+
// sync documents if online
43+
if (store.state.online && store.state.auth.user) {
44+
debounce('sync', () => {
45+
store.dispatch(SYNC)
46+
})
47+
}
48+
}
49+
4850
export default syncPlugin

0 commit comments

Comments
 (0)