@knowlearning/agents 0.4.10 → 0.4.12
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/vue/3/component.js +40 -42
- package/vue/3/component.shim.js +0 -4
package/package.json
CHANGED
package/vue/3/component.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import content from "./content.vue"
|
|
1
|
+
import { watchEffect, defineAsyncComponent } from 'vue'
|
|
3
2
|
|
|
4
3
|
// TODO: probably want to make this a util, and better fleshed out (with white instead of blacklist)
|
|
5
4
|
function isScopeSerializable(v) {
|
|
@@ -8,51 +7,50 @@ function isScopeSerializable(v) {
|
|
|
8
7
|
)
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
export default
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
23
25
|
}
|
|
24
|
-
return state
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
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
|
+
})
|
|
46
47
|
})
|
|
47
|
-
})
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
return refs
|
|
50
|
+
}
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
|
-
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
app.component('Content', content)
|
|
57
|
-
app.mount(document.body)
|
|
54
|
+
return component
|
|
55
|
+
})
|
|
58
56
|
}
|
package/vue/3/component.shim.js
DELETED