-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (51 loc) · 1.37 KB
/
Copy pathindex.js
File metadata and controls
59 lines (51 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { inject } from 'vue'
function SET_STATE(state, payload) {
Object.keys(state).forEach((key) => {
state[key] = payload[key]
})
}
function register(config, rootKey) {
const name = config.name
const root = inject(rootKey || 'store')
const namespace = (typeof name === 'string' ? name : name.join('/')) + '/'
let map = root._modulesNamespaceMap
if (!map[namespace]) {
root.registerModule(name, config)
}
const context = map[namespace].context
return Object.assign(context, {
setState(payload) {
context.commit('SET_STATE', payload)
},
})
}
export function defineModule(root, config) {
config.namespaced = true
config.mutations = Object.assign({ SET_STATE }, config.mutations)
return config
// return {
// option: config,
// registerModule(rootKey) {
// register(config.name, config, rootKey)
// },
// useModule(rootKey) {
// return useModule(config.name, rootKey)
// }
// }
}
export function useModule(config, rootKey) {
let context
return function () {
context = context || register(config, rootKey)
return context
}
}
export function defineStore(config) {
return {
option: config,
addModules: function (modules) {
config.modules = Object.assign({}, config.modules, modules)
return config
}
}
}