@knowlearning/agents 0.9.7 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/persistence/vuex.js +5 -4
package/package.json
CHANGED
package/persistence/vuex.js
CHANGED
|
@@ -9,12 +9,12 @@ async function scopeIsUninitialized(scope) {
|
|
|
9
9
|
return Object.keys(await Agent.state(scope)).length === 0
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export default async function (storeDefinition, scope
|
|
12
|
+
export default async function (storeDefinition, scope) {
|
|
13
13
|
let state = copy(await Agent.state(scope))
|
|
14
14
|
const scopedPaths = getScopedPaths(storeDefinition)
|
|
15
15
|
const stateAttachedStore = await attachModuleState(state, storeDefinition, scopedPaths)
|
|
16
16
|
const s = stateAttachedStore.state
|
|
17
|
-
const originalState = s instanceof Function ? s() :
|
|
17
|
+
const originalState = s instanceof Function ? s() : s
|
|
18
18
|
|
|
19
19
|
const handlePatch = patch => {
|
|
20
20
|
patch.forEach(({ path }) => path.unshift('active'))
|
|
@@ -72,11 +72,12 @@ async function attachModuleState(state, module, scopedPaths, path='') {
|
|
|
72
72
|
const ephemeralPaths = descendantPaths(path, scopedPaths)
|
|
73
73
|
state = MutableProxy(copy(initState), handlePatch, ephemeralPaths)
|
|
74
74
|
if (await scopeIsUninitialized(scope)) {
|
|
75
|
-
Object.assign(state, module.state())
|
|
75
|
+
Object.assign(state, module.state instanceof Function ? module.state() : module.state)
|
|
76
76
|
}
|
|
77
77
|
return { ...module, state: () => state }
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
// TODO: better check for initialized state
|
|
80
|
+
else return Object.keys(state).length ? { ...module, state: () => state } : module
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
function getScopedPaths(module, path="", paths={}) {
|