Skip to content

Commit 10a909f

Browse files
Merge pull request #7402 from nextcloud/backport/7383/stable30
[stable30] refactor: convert store to factory functions
2 parents da33b0a + b5f8e20 commit 10a909f

7 files changed

Lines changed: 932 additions & 904 deletions

File tree

src/init-reference.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { registerWidget, registerCustomPickerElement, NcCustomPickerRenderResult } from '@nextcloud/vue/dist/Functions/registerReference.js'
77
import { translate, translatePlural } from '@nextcloud/l10n'
8+
import storeFactory from './store/main.js'
89

910
import './shared-init.js'
1011

@@ -51,6 +52,7 @@ registerWidget('deck-board', async (el, { richObjectType, richObject, accessible
5152
const { default: BoardReferenceWidget } = await import('./views/BoardReferenceWidget.vue')
5253
const Widget = await prepareVue(BoardReferenceWidget)
5354
boardWidgets[el] = new Widget({
55+
store: storeFactory(),
5456
propsData: {
5557
richObjectType,
5658
richObject,

src/main.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55
import Vue from 'vue'
66
import App from './App.vue'
77
import router from './router.js'
8-
import store from './store/main.js'
8+
import storeFactory from './store/main.js'
99
import { sync } from 'vuex-router-sync'
1010
import { translate, translatePlural } from '@nextcloud/l10n'
1111
import { showError } from '@nextcloud/dialogs'
1212
import { subscribe } from '@nextcloud/event-bus'
1313
import ClickOutside from 'vue-click-outside'
1414
import './shared-init.js'
1515
import './models/index.js'
16-
import './sessions.js'
16+
import { initSessions } from './sessions.js'
1717

1818
// the server snap.js conflicts with vertical scrolling so we disable it
1919
document.body.setAttribute('data-snap-ignore', 'true')
2020

21+
const store = storeFactory()
2122
sync(store, router)
23+
initSessions(store)
2224

2325
Vue.prototype.t = translate
2426
Vue.prototype.n = translatePlural

src/sessions.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { listen } from '@nextcloud/notify_push'
77
import { sessionApi } from './services/SessionApi.js'
8-
import store from './store/main.js'
98
import axios from '@nextcloud/axios'
109

1110
const SESSION_INTERVAL = 90 // in seconds
@@ -14,6 +13,8 @@ let hasPush = false
1413

1514
let syncRunning = false
1615

16+
let store = null
17+
1718
/**
1819
* used to verify, whether an event is originated by ourselves
1920
*
@@ -28,28 +29,35 @@ function isOurSessionToken(token) {
2829
}
2930
}
3031

31-
hasPush = listen('deck_board_update', (name, body) => {
32-
// ignore update events which we have triggered ourselves
33-
if (isOurSessionToken(body._causingSessionToken)) return
32+
/**
33+
*
34+
* @param storeInstance
35+
*/
36+
export function initSessions(storeInstance) {
37+
store = storeInstance
38+
hasPush = listen('deck_board_update', (name, body) => {
39+
// ignore update events which we have triggered ourselves
40+
if (isOurSessionToken(body._causingSessionToken)) return
3441

35-
// only handle update events for the currently open board
36-
const currentBoardId = store.state.currentBoard?.id
37-
if (body.id !== currentBoardId) return
42+
// only handle update events for the currently open board
43+
const currentBoardId = store.state.currentBoard?.id
44+
if (body.id !== currentBoardId) return
3845

39-
store.dispatch('refreshBoard', currentBoardId)
40-
})
46+
store.dispatch('refreshBoard', currentBoardId)
47+
})
4148

42-
listen('deck_card_update', (name, body) => {
49+
listen('deck_card_update', (name, body) => {
4350

44-
// ignore update events which we have triggered ourselves
45-
if (isOurSessionToken(body._causingSessionToken)) return
51+
// ignore update events which we have triggered ourselves
52+
if (isOurSessionToken(body._causingSessionToken)) return
4653

47-
// only handle update events for the currently open board
48-
const currentBoardId = store.state.currentBoard?.id
49-
if (body.boardId !== currentBoardId) return
54+
// only handle update events for the currently open board
55+
const currentBoardId = store.state.currentBoard?.id
56+
if (body.boardId !== currentBoardId) return
5057

51-
store.dispatch('loadStacks', currentBoardId)
52-
})
58+
store.dispatch('loadStacks', currentBoardId)
59+
})
60+
}
5361

5462
/**
5563
* is the notify_push app active and can

0 commit comments

Comments
 (0)