-
Notifications
You must be signed in to change notification settings - Fork 24
/
_template.js
60 lines (56 loc) · 1.74 KB
/
_template.js
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
60
import { defaultMutations } from 'vuex-easy-access'
import easyAccessConf from '@config/vuexEasyAccess'
function initialState () {
// ❗️ properties > 1 level deep are not reset with resetStateData()
return {
stateValue: null,
'1': {'2': {'3': {'4': {'5': null}}}},
colors: {primary: 'black'}
}
}
export default {
namespaced: true,
state: initialState(),
mounted () {
console.log('this → ', this)
},
mutations:
{
resetStateData (state) {
const newState = initialState()
Object.assign(state, newState)
},
...defaultMutations(initialState(), easyAccessConf)
},
actions:
{
'setColors.primary': ({state, commit, dispatch}, newColor) => {
// dispatch('patchToServer', state.colors.primary, {root: true})
// console.log('patched')
return dispatch('set/colors.primary', newColor)
},
doIt (
{state, getters, rootState, rootGetters, commit, dispatch},
{id} = {}
) {
// getters.someOtherGetter // -> 'foo/someOtherGetter'
// rootGetters.someOtherGetter // -> 'someOtherGetter'
dispatch('someOtherAction') // -> 'foo/someOtherAction'
dispatch('someOtherAction', null, { root: true }) // -> 'someOtherAction'
commit('someMutation') // -> 'foo/someMutation'
commit('someMutation', null, { root: true }) // -> 'someMutation'
}
},
getters:
{
'colors.primary': (state) => {
// console.log('gotit! ')
// return hexToReadableColor(state.colors.primary)
return state.colors.primary + 'is the color bitchez'
},
getIt: (state, getters, rootState, rootGetters) => (id) => {
// getters.someOtherGetter // -> 'foo/someOtherGetter'
// rootGetters.someOtherGetter // -> 'someOtherGetter'
}
}
}