@knowlearning/agents 0.9.133 → 0.9.134

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.133",
3
+ "version": "0.9.134",
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>