@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 +1 -1
- package/vue/3/components/scope.vue +33 -34
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
17
|
+
const value = ref(undefined)
|
|
18
|
+
const loading = ref(true)
|
|
19
|
+
let stopWatching
|
|
40
20
|
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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>
|