1
|
|
|
/** |
2
|
|
|
* @package admin |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
import Vue from 'vue'; |
6
|
|
|
import Vuex from 'vuex'; |
7
|
|
|
import type { Module } from 'vuex'; |
8
|
|
|
import VuexModules from 'src/app/state/index'; |
9
|
|
|
import type { FullState } from 'src/core/factory/state.factory'; |
10
|
|
|
|
11
|
|
|
// eslint-disable-next-line sw-deprecation-rules/private-feature-declarations |
12
|
|
|
export default function initState() { |
13
|
|
|
initVuexState(Shopware.State); |
14
|
|
|
// @ts-expect-error - all vuex modules are defined |
15
|
|
|
initVuexModules(VuexModules, Shopware.State); |
16
|
|
|
|
17
|
|
|
return true; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
function initVuexState(state: FullState) { |
21
|
|
|
Vue.use(Vuex); |
22
|
|
|
|
23
|
|
|
const store = new Vuex.Store<VuexRootState>({ |
24
|
|
|
modules: {}, |
25
|
|
|
strict: false, |
26
|
|
|
}); |
27
|
|
|
|
28
|
|
|
// eslint-disable-next-line max-len |
29
|
|
|
/* eslint-disable @typescript-eslint/no-unsafe-return, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument, max-len */ |
30
|
|
|
state._registerPrivateProperty('_store', store); |
31
|
|
|
state._registerProperty('list', () => Object.keys(store.state)); |
32
|
|
|
state._registerProperty('get', <N extends keyof VuexRootState>(name: N) => store.state[name]); |
33
|
|
|
state._registerGetterMethod('getters', () => store.getters); |
34
|
|
|
state._registerProperty('commit', (...args: Parameters<typeof store.commit>) => store.commit(...args)); |
35
|
|
|
state._registerProperty('dispatch', (...args: Parameters<typeof store.dispatch>) => store.dispatch(...args)); |
36
|
|
|
state._registerProperty('watch', (...args: Parameters<typeof store.watch>) => store.watch(...args)); |
37
|
|
|
state._registerProperty('subscribe', (...args: Parameters<typeof store.subscribe>) => store.subscribe(...args)); |
38
|
|
|
state._registerProperty('subscribeAction', (...args: Parameters<typeof store.subscribeAction>) => store.subscribeAction(...args)); |
39
|
|
|
state._registerProperty('registerModule', (...args: Parameters<typeof store.registerModule>) => store.registerModule(...args)); |
40
|
|
|
state._registerProperty('unregisterModule', (...args: Parameters<typeof store.unregisterModule>) => store.unregisterModule(...args)); |
41
|
|
|
/* eslint-enable @typescript-eslint/no-unsafe-return, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument, max-len */ |
42
|
|
|
|
43
|
|
|
return state; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
function initVuexModules(modules: { [moduleName: string]: Module<keyof VuexRootState, VuexRootState> }, state: FullState) { |
47
|
|
|
Object.entries(modules).forEach(([moduleName, module]) => { |
48
|
|
|
state.registerModule(moduleName, module); |
49
|
|
|
}); |
50
|
|
|
} |
51
|
|
|
|