@knowlearning/agents 0.9.133 → 0.9.135

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/watch.js CHANGED
@@ -13,20 +13,13 @@ export default function({ metadata, environment, state, watchers, synced, sentUp
13
13
  let removed = false
14
14
  metadata(scope, user, domain)
15
15
  .then(async ({ ii }) => {
16
- if (removed) return
17
-
18
16
  const { auth: { user: u }, domain: d } = await environment()
19
- qualifiedScope = isUUID(scope) ? scope : `${!domain || domain === d ? '' : domain}/${!user || user === u ? '' : user}/${scope}`
17
+ const state = await statePromise
20
18
 
21
- fn({
22
- scope,
23
- user,
24
- domain,
25
- state: await statePromise,
26
- patch: null,
27
- ii
28
- })
19
+ if (removed) return
29
20
 
21
+ qualifiedScope = isUUID(scope) ? scope : `${!domain || domain === d ? '' : domain}/${!user || user === u ? '' : user}/${scope}`
22
+ fn({ scope, user, domain, state, patch: null, ii })
30
23
  if (sentUpdates) sentUpdates[qualifiedScope] = ii
31
24
 
32
25
  if (removed) return
@@ -37,7 +30,7 @@ export default function({ metadata, environment, state, watchers, synced, sentUp
37
30
 
38
31
  return () => {
39
32
  removed = true
40
- return removeWatcher(qualifiedScope, fn)
33
+ if (qualifiedScope) removeWatcher(qualifiedScope, fn)
41
34
  }
42
35
  }
43
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.133",
3
+ "version": "0.9.135",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",
@@ -4,47 +4,46 @@
4
4
  </slot>
5
5
  </template>
6
6
 
7
- <script>
8
- import { ref, watch, onMounted, onBeforeUnmount, computed } from 'vue'
7
+ <script setup>
8
+ import { ref, watch, onMounted, onBeforeUnmount, computed } from 'vue'
9
9
 
10
- export default {
11
- props: {
10
+ const props = defineProps({
12
11
  id: String,
13
12
  path: { type: Array, default: [] },
14
13
  placeholder: { type: String, default: '' },
15
14
  metadata: { type: Boolean, default: false }
16
- },
17
- setup(props) {
18
- const value = ref(undefined)
19
- const loading = ref(true)
20
- let stopWatching
21
- let stopWatchingAttempted = false
22
-
23
- const startWatching = async () => {
24
- if (stopWatching) stopWatching()
25
- if (props.metadata) {
26
- const metadata = await Agent.metadata(props.id)
27
- value.value = props.path.length === 1 ? metadata[props.path[0]] : metadata
28
- } else {
29
- stopWatching = Agent.watch([props.id, ...props.path], val => {
30
- if (stopWatchingAttempted) console.warn('Watcher not stopped for vueScopeComponent')
31
- else value.value = val
32
- })
33
- }
34
- loading.value = false
35
- }
15
+ })
36
16
 
37
- watch( [() => props.id, () => props.path], startWatching, { deep: true })
38
- onMounted(() => startWatching())
39
- onBeforeUnmount(() => stopWatching && stopWatching())
17
+ const value = ref(undefined)
18
+ const loading = ref(true)
19
+ let stopWatching
40
20
 
41
- const defaultRenderedValue = computed(() => {
42
- if (loading.value) return 'loading'
43
- else if (value.value === null && props.placeholder) return props.placeholder
44
- else return value.value
45
- })
21
+ const startWatching = async () => {
22
+ if (stopWatching) stopWatching()
46
23
 
47
- return { loading, value, defaultRenderedValue }
24
+ if (props.id === undefined) {
25
+ stopWatching = undefined
26
+ value.value = undefined
27
+ }
28
+ else if (props.metadata) {
29
+ const metadata = await Agent.metadata(props.id)
30
+ value.value = props.path.length === 1 ? metadata[props.path[0]] : metadata
31
+ } else {
32
+ stopWatching = Agent.watch([props.id, ...props.path], v => value.value = v)
33
+ }
34
+ loading.value = false
48
35
  }
49
- };
36
+
37
+ watch( [() => props.id, () => props.path], startWatching, { deep: true })
38
+
39
+ onBeforeUnmount(() => stopWatching && stopWatching())
40
+
41
+ startWatching()
42
+
43
+ const defaultRenderedValue = computed(() => {
44
+ if (loading.value) return 'loading'
45
+ else if (value.value === null && props.placeholder) return props.placeholder
46
+ else return value.value
47
+ })
48
+
50
49
  </script>