@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.
@@ -26,9 +26,9 @@ export default () => {
26
26
  reboot: () => window.location.reload()
27
27
  })
28
28
 
29
- const { state, mutate } = agent
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.4.11",
3
+ "version": "0.4.13",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",
@@ -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 async function (module, scope) {
11
- const component = module.default ? { ...module.default } : { ...module } // copy component since we will mess with mounted and data functions
12
-
13
- if (!component.ephemeral) {
14
- const state = await Agent.mutate(scope)
15
-
16
- if (component.data) {
17
- const origDataFn = component.data
18
- component.data = function dataProxy() {
19
- if (Object.keys(state).length === 0) {
20
- const startState = origDataFn.apply(this, arguments)
21
- Object.assign(state, startState)
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
- else if (component.setup) {
27
- const origSetupFn = component.setup
28
- const isReactiveRef = r => r && r.__v_isRef
29
- 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...)
30
- let refs = origSetupFn.call(this, a, b)
31
-
32
- Object
33
- .entries(state)
34
- .filter(([k]) => isReactiveRef(refs[k]))
35
- .forEach(([k, v]) => refs[k].value = v)
36
-
37
- Object
38
- .entries(refs)
39
- .filter(([_,r]) => isReactiveRef(r) && isScopeSerializable(r.value))
40
- .forEach(([key, ref]) => {
41
- watchEffect(() => {
42
- if (state[key] !== ref.value) {
43
- state[key] = ref.value
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
- return refs
49
+ return refs
50
+ }
49
51
  }
50
52
  }
51
- }
52
53
 
53
- return component
54
+ return component
55
+ })
54
56
  }