@knowlearning/agents 0.4.11 → 0.4.13
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/agents/browser/root.js +2 -2
- package/package.json +1 -1
- package/vue/3/component.js +40 -38
package/agents/browser/root.js
CHANGED
|
@@ -26,9 +26,9 @@ export default () => {
|
|
|
26
26
|
reboot: () => window.location.reload()
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
-
const { state
|
|
29
|
+
const { state } = agent
|
|
30
|
+
// TODO: remove agent.state proxy here as part of "get rid of default scope" work
|
|
30
31
|
agent.state = (scope=host,user,domain) => state(scope, user, domain)
|
|
31
|
-
agent.mutate = (scope=host) => mutate(scope)
|
|
32
32
|
agent.local = () => {
|
|
33
33
|
if (isLocal()) return
|
|
34
34
|
|
package/package.json
CHANGED
package/vue/3/component.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { watchEffect } from 'vue'
|
|
1
|
+
import { watchEffect, defineAsyncComponent } from 'vue'
|
|
2
2
|
|
|
3
3
|
// TODO: probably want to make this a util, and better fleshed out (with white instead of blacklist)
|
|
4
4
|
function isScopeSerializable(v) {
|
|
@@ -7,48 +7,50 @@ function isScopeSerializable(v) {
|
|
|
7
7
|
)
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export default
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
export default function (module, scope) {
|
|
11
|
+
return defineAsyncComponent(async function () {
|
|
12
|
+
const component = module.default ? { ...module.default } : { ...module } // copy component since we will mess with mounted and data functions
|
|
13
|
+
|
|
14
|
+
if (!component.ephemeral) {
|
|
15
|
+
const state = await Agent.mutate(scope)
|
|
16
|
+
|
|
17
|
+
if (component.data) {
|
|
18
|
+
const origDataFn = component.data
|
|
19
|
+
component.data = function dataProxy() {
|
|
20
|
+
if (Object.keys(state).length === 0) {
|
|
21
|
+
const startState = origDataFn.apply(this, arguments)
|
|
22
|
+
Object.assign(state, startState)
|
|
23
|
+
}
|
|
24
|
+
return state
|
|
22
25
|
}
|
|
23
|
-
return state
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
27
|
+
else if (component.setup) {
|
|
28
|
+
const origSetupFn = component.setup
|
|
29
|
+
const isReactiveRef = r => r && r.__v_isRef
|
|
30
|
+
component.setup = function setupProxy(a, b) { // need to specifically add this here, otherwise second argument not passed in arguments array (probably because of webpack optimization...)
|
|
31
|
+
let refs = origSetupFn.call(this, a, b)
|
|
32
|
+
|
|
33
|
+
Object
|
|
34
|
+
.entries(state)
|
|
35
|
+
.filter(([k]) => isReactiveRef(refs[k]))
|
|
36
|
+
.forEach(([k, v]) => refs[k].value = v)
|
|
37
|
+
|
|
38
|
+
Object
|
|
39
|
+
.entries(refs)
|
|
40
|
+
.filter(([_,r]) => isReactiveRef(r) && isScopeSerializable(r.value))
|
|
41
|
+
.forEach(([key, ref]) => {
|
|
42
|
+
watchEffect(() => {
|
|
43
|
+
if (state[key] !== ref.value) {
|
|
44
|
+
state[key] = ref.value
|
|
45
|
+
}
|
|
46
|
+
})
|
|
45
47
|
})
|
|
46
|
-
})
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
return refs
|
|
50
|
+
}
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
|
-
}
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
return component
|
|
55
|
+
})
|
|
54
56
|
}
|