@knowlearning/agents 0.9.6 → 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.
|
@@ -40,8 +40,6 @@ export default function EmbeddedAgent() {
|
|
|
40
40
|
addEventListener('message', async ({ data }) => {
|
|
41
41
|
if (data.type === 'auth') {
|
|
42
42
|
// TODO: switch to access_token
|
|
43
|
-
debugger
|
|
44
|
-
console.log('localStorage "state", data.state, token, location --->>>', localStorage.getItem('state'), data.state, data.token, window.location)
|
|
45
43
|
if (localStorage.getItem('state') === data.state) {
|
|
46
44
|
localStorage.setItem('token', data.token)
|
|
47
45
|
}
|
package/package.json
CHANGED
package/persistence/vuex.js
CHANGED
|
@@ -5,16 +5,16 @@ import MutableProxy from './json.js'
|
|
|
5
5
|
const copy = x => JSON.parse(JSON.stringify(x))
|
|
6
6
|
|
|
7
7
|
async function scopeIsUninitialized(scope) {
|
|
8
|
-
|
|
9
|
-
return
|
|
8
|
+
// TODO: better check
|
|
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={}) {
|