@ng-org/orm 0.1.2-alpha.7 → 0.1.2-alpha.9
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/README.md +74 -92
- package/dist/connector/applyPatches.d.ts +13 -4
- package/dist/connector/applyPatches.d.ts.map +1 -1
- package/dist/connector/applyPatches.js +9 -5
- package/dist/connector/discrete/discreteOrmSubscriptionHandler.d.ts +156 -0
- package/dist/connector/discrete/discreteOrmSubscriptionHandler.d.ts.map +1 -0
- package/dist/connector/discrete/{discreteOrmConnectionHandler.js → discreteOrmSubscriptionHandler.js} +130 -19
- package/dist/connector/getObjects.js +2 -2
- package/dist/connector/initNg.d.ts +35 -0
- package/dist/connector/initNg.d.ts.map +1 -1
- package/dist/connector/initNg.js +35 -0
- package/dist/connector/insertObject.js +2 -2
- package/dist/connector/ormSubscriptionHandler.d.ts +166 -0
- package/dist/connector/ormSubscriptionHandler.d.ts.map +1 -0
- package/dist/connector/{ormConnectionHandler.js → ormSubscriptionHandler.js} +157 -32
- package/dist/frontendAdapters/react/useDiscrete.d.ts +89 -69
- package/dist/frontendAdapters/react/useDiscrete.d.ts.map +1 -1
- package/dist/frontendAdapters/react/useDiscrete.js +103 -81
- package/dist/frontendAdapters/react/useShape.d.ts +55 -55
- package/dist/frontendAdapters/react/useShape.d.ts.map +1 -1
- package/dist/frontendAdapters/react/useShape.js +71 -73
- package/dist/frontendAdapters/svelte/useDiscrete.svelte.d.ts +80 -71
- package/dist/frontendAdapters/svelte/useDiscrete.svelte.d.ts.map +1 -1
- package/dist/frontendAdapters/svelte/useDiscrete.svelte.js +102 -91
- package/dist/frontendAdapters/svelte/useShape.svelte.d.ts +70 -64
- package/dist/frontendAdapters/svelte/useShape.svelte.d.ts.map +1 -1
- package/dist/frontendAdapters/svelte/useShape.svelte.js +73 -62
- package/dist/frontendAdapters/svelte4/index.d.ts +5 -0
- package/dist/frontendAdapters/svelte4/index.d.ts.map +1 -0
- package/dist/frontendAdapters/svelte4/index.js +12 -0
- package/dist/frontendAdapters/svelte4/useDiscrete.svelte.d.ts +85 -0
- package/dist/frontendAdapters/svelte4/useDiscrete.svelte.d.ts.map +1 -0
- package/dist/frontendAdapters/svelte4/useDiscrete.svelte.js +124 -0
- package/dist/frontendAdapters/svelte4/useShape.svelte.d.ts +76 -0
- package/dist/frontendAdapters/svelte4/useShape.svelte.d.ts.map +1 -0
- package/dist/frontendAdapters/svelte4/useShape.svelte.js +84 -0
- package/dist/frontendAdapters/vue/useDiscrete.d.ts +87 -80
- package/dist/frontendAdapters/vue/useDiscrete.d.ts.map +1 -1
- package/dist/frontendAdapters/vue/useDiscrete.js +96 -84
- package/dist/frontendAdapters/vue/useShape.d.ts +57 -63
- package/dist/frontendAdapters/vue/useShape.d.ts.map +1 -1
- package/dist/frontendAdapters/vue/useShape.js +59 -64
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/types.d.ts +17 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +11 -2
- package/package.json +7 -3
- package/dist/connector/discrete/discreteOrmConnectionHandler.d.ts +0 -45
- package/dist/connector/discrete/discreteOrmConnectionHandler.d.ts.map +0 -1
- package/dist/connector/ormConnectionHandler.d.ts +0 -48
- package/dist/connector/ormConnectionHandler.d.ts.map +0 -1
|
@@ -1,92 +1,99 @@
|
|
|
1
|
-
import { MaybeRefOrGetter } from "vue";
|
|
2
|
-
import {
|
|
3
|
-
import { DiscreteArray, DiscreteObject } from "../../types.ts";
|
|
1
|
+
import { MaybeRefOrGetter, ToRefs } from "vue";
|
|
2
|
+
import { DiscreteRootObject } from "../../types.ts";
|
|
4
3
|
/**
|
|
5
|
-
* Hook to subscribe to discrete (JSON) CRDT
|
|
4
|
+
* Hook to subscribe to an existing discrete (JSON) CRDT document.
|
|
6
5
|
* You can modify the returned object like any other JSON object. Changes are immediately
|
|
7
|
-
* reflected in the CRDT.
|
|
6
|
+
* reflected in the CRDT document.
|
|
8
7
|
*
|
|
9
8
|
* Establishes a 2-way binding: Modifications to the object are immediately committed,
|
|
10
|
-
* changes coming from the
|
|
9
|
+
* changes coming from the engine (or other components) cause an immediate rerender.
|
|
11
10
|
*
|
|
12
11
|
* In comparison to `useShape`, discrete CRDTs are untyped.
|
|
13
12
|
* You can put any JSON data inside and need to validate the schema yourself.
|
|
14
13
|
*
|
|
15
|
-
* @param documentId The IRI of the
|
|
16
|
-
* @returns An object that contains as `data` the reactive DeepSignal object.
|
|
14
|
+
* @param documentId The IRI of the CRDT document or `undefined` as MaybeRefOrGetter.
|
|
15
|
+
* @returns An object that contains as `data` the reactive DeepSignal object or undefined if not loaded yet or `documentId` is undefined.
|
|
17
16
|
*
|
|
18
17
|
*@example
|
|
19
|
-
```html
|
|
20
|
-
<script lang="ts">
|
|
21
|
-
// We assume you have created a CRDT document already, as below.
|
|
22
|
-
// const documentId = await ng.doc_create(
|
|
23
|
-
// session_id,
|
|
24
|
-
// crdt, // "Automerge" | "YMap" | "YArray"
|
|
25
|
-
// crdt === "Automerge" ? "data:json" : crdt === "YMap ? "data:map" : "data:array",
|
|
26
|
-
// "store",
|
|
27
|
-
// undefined
|
|
28
|
-
// );
|
|
29
|
-
const {
|
|
30
|
-
|
|
31
|
-
// If document is new, we need to set up the basic structure.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
</
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
18
|
+
* ```html
|
|
19
|
+
* <script lang="ts">
|
|
20
|
+
* // We assume you have created a CRDT document already, as below.
|
|
21
|
+
* // const documentId = await ng.doc_create(
|
|
22
|
+
* // session_id,
|
|
23
|
+
* // crdt, // "Automerge" | "YMap" | "YArray"
|
|
24
|
+
* // crdt === "Automerge" ? "data:json" : crdt === "YMap ? "data:map" : "data:array",
|
|
25
|
+
* // "store",
|
|
26
|
+
* // undefined
|
|
27
|
+
* // );
|
|
28
|
+
* const { doc } = useDiscrete(documentId);
|
|
29
|
+
*
|
|
30
|
+
* // If document is new, we need to set up the basic structure.
|
|
31
|
+
* effect(() => {
|
|
32
|
+
* if (doc.value && !doc.value.expenses) {
|
|
33
|
+
* doc.value.expenses = [];
|
|
34
|
+
* }
|
|
35
|
+
* })
|
|
36
|
+
*
|
|
37
|
+
* const createExpense = () => {
|
|
38
|
+
* // Note that we use *expense["@id"]* as a key in the expense list.
|
|
39
|
+
* // Every object added to a CRDT array gets a stable `@id` property assigned
|
|
40
|
+
* // which you can use for referencing objects in arrays even as
|
|
41
|
+
* // objects are removed or added from the array.
|
|
42
|
+
* // The `@id` is an IRI with the schema `<documentId>:d:<object-specific id>`.
|
|
43
|
+
* // Since the `@id` is generated in the engine, the object is
|
|
44
|
+
* // *preliminarily given a mock id* which will be replaced immediately.
|
|
45
|
+
* doc.value.expenses.push({
|
|
46
|
+
* title: "New expense",
|
|
47
|
+
* date: new Date().toISOString(),
|
|
48
|
+
* });
|
|
49
|
+
* };
|
|
50
|
+
* </script>
|
|
51
|
+
*
|
|
52
|
+
* <template>
|
|
53
|
+
* <div v-if="!doc">
|
|
54
|
+
* Loading...
|
|
55
|
+
* </div>
|
|
56
|
+
* <div v-else>
|
|
57
|
+
* <p v-if="expenses.length === 0">
|
|
58
|
+
* No expenses yet.
|
|
59
|
+
* </p>
|
|
60
|
+
* <template v-else>
|
|
61
|
+
* <button
|
|
62
|
+
* @click={() => createExpense()}
|
|
63
|
+
* >
|
|
64
|
+
* + Add expense
|
|
65
|
+
* </button>
|
|
66
|
+
* <ExpenseCard
|
|
67
|
+
* v-for="expense in expenses"
|
|
68
|
+
* :key="expense['@id']"
|
|
69
|
+
* :expense="expense"
|
|
70
|
+
* />
|
|
71
|
+
* </template>
|
|
72
|
+
* </div>
|
|
73
|
+
* </template>
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* In the `ExpenseCard` component:
|
|
77
|
+
* ```html
|
|
78
|
+
* <script lang="ts">
|
|
79
|
+
* const { expense } = defineProps<{
|
|
80
|
+
* expense: DeepSignal<Expense>;
|
|
81
|
+
* }>();
|
|
82
|
+
*
|
|
83
|
+
* // If you modify expense in the component,
|
|
84
|
+
* // the changes are immediately propagated to the other components
|
|
85
|
+
* // And persisted in the database.
|
|
86
|
+
* </script>
|
|
87
|
+
*
|
|
88
|
+
* <template>
|
|
89
|
+
* <input
|
|
90
|
+
* v-model="expense.title"
|
|
91
|
+
* placeholder="Expense title"
|
|
92
|
+
* />
|
|
93
|
+
* </template>
|
|
94
|
+
* ```
|
|
88
95
|
*/
|
|
89
|
-
export declare function useDiscrete(documentId: MaybeRefOrGetter<string | undefined>): {
|
|
90
|
-
|
|
91
|
-
}
|
|
96
|
+
export declare function useDiscrete(documentId: MaybeRefOrGetter<string | undefined>): ToRefs<{
|
|
97
|
+
doc: DiscreteRootObject;
|
|
98
|
+
}>;
|
|
92
99
|
//# sourceMappingURL=useDiscrete.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDiscrete.d.ts","sourceRoot":"","sources":["../../../src/frontendAdapters/vue/useDiscrete.ts"],"names":[],"mappings":"AAUA,OAAO,
|
|
1
|
+
{"version":3,"file":"useDiscrete.d.ts","sourceRoot":"","sources":["../../../src/frontendAdapters/vue/useDiscrete.ts"],"names":[],"mappings":"AAUA,OAAO,EAEH,gBAAgB,EAGhB,MAAM,EAIT,MAAM,KAAK,CAAC;AAGb,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4FG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,gBAAgB,CAAC,MAAM,GAAG,SAAS,CAAC,GAmBlD,MAAM,CAAC;IAAE,GAAG,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAC5D"}
|
|
@@ -7,105 +7,117 @@
|
|
|
7
7
|
// notice may not be copied, modified, or distributed except
|
|
8
8
|
// according to those terms.
|
|
9
9
|
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
10
|
-
import { computed, onBeforeUnmount, toValue } from "vue";
|
|
10
|
+
import { computed, onBeforeUnmount, shallowReactive, toRefs, toValue, watchEffect, } from "vue";
|
|
11
11
|
import { useDeepSignal } from "@ng-org/alien-deepsignals/vue";
|
|
12
|
-
import {
|
|
13
|
-
const EMPTY_OBJECT = {};
|
|
12
|
+
import { DiscreteOrmSubscription } from "../../connector/discrete/discreteOrmSubscriptionHandler.js";
|
|
14
13
|
/**
|
|
15
|
-
* Hook to subscribe to discrete (JSON) CRDT
|
|
14
|
+
* Hook to subscribe to an existing discrete (JSON) CRDT document.
|
|
16
15
|
* You can modify the returned object like any other JSON object. Changes are immediately
|
|
17
|
-
* reflected in the CRDT.
|
|
16
|
+
* reflected in the CRDT document.
|
|
18
17
|
*
|
|
19
18
|
* Establishes a 2-way binding: Modifications to the object are immediately committed,
|
|
20
|
-
* changes coming from the
|
|
19
|
+
* changes coming from the engine (or other components) cause an immediate rerender.
|
|
21
20
|
*
|
|
22
21
|
* In comparison to `useShape`, discrete CRDTs are untyped.
|
|
23
22
|
* You can put any JSON data inside and need to validate the schema yourself.
|
|
24
23
|
*
|
|
25
|
-
* @param documentId The IRI of the
|
|
26
|
-
* @returns An object that contains as `data` the reactive DeepSignal object.
|
|
24
|
+
* @param documentId The IRI of the CRDT document or `undefined` as MaybeRefOrGetter.
|
|
25
|
+
* @returns An object that contains as `data` the reactive DeepSignal object or undefined if not loaded yet or `documentId` is undefined.
|
|
27
26
|
*
|
|
28
27
|
*@example
|
|
29
|
-
```html
|
|
30
|
-
<script lang="ts">
|
|
31
|
-
// We assume you have created a CRDT document already, as below.
|
|
32
|
-
// const documentId = await ng.doc_create(
|
|
33
|
-
// session_id,
|
|
34
|
-
// crdt, // "Automerge" | "YMap" | "YArray"
|
|
35
|
-
// crdt === "Automerge" ? "data:json" : crdt === "YMap ? "data:map" : "data:array",
|
|
36
|
-
// "store",
|
|
37
|
-
// undefined
|
|
38
|
-
// );
|
|
39
|
-
const {
|
|
40
|
-
|
|
41
|
-
// If document is new, we need to set up the basic structure.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
</
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
28
|
+
* ```html
|
|
29
|
+
* <script lang="ts">
|
|
30
|
+
* // We assume you have created a CRDT document already, as below.
|
|
31
|
+
* // const documentId = await ng.doc_create(
|
|
32
|
+
* // session_id,
|
|
33
|
+
* // crdt, // "Automerge" | "YMap" | "YArray"
|
|
34
|
+
* // crdt === "Automerge" ? "data:json" : crdt === "YMap ? "data:map" : "data:array",
|
|
35
|
+
* // "store",
|
|
36
|
+
* // undefined
|
|
37
|
+
* // );
|
|
38
|
+
* const { doc } = useDiscrete(documentId);
|
|
39
|
+
*
|
|
40
|
+
* // If document is new, we need to set up the basic structure.
|
|
41
|
+
* effect(() => {
|
|
42
|
+
* if (doc.value && !doc.value.expenses) {
|
|
43
|
+
* doc.value.expenses = [];
|
|
44
|
+
* }
|
|
45
|
+
* })
|
|
46
|
+
*
|
|
47
|
+
* const createExpense = () => {
|
|
48
|
+
* // Note that we use *expense["@id"]* as a key in the expense list.
|
|
49
|
+
* // Every object added to a CRDT array gets a stable `@id` property assigned
|
|
50
|
+
* // which you can use for referencing objects in arrays even as
|
|
51
|
+
* // objects are removed or added from the array.
|
|
52
|
+
* // The `@id` is an IRI with the schema `<documentId>:d:<object-specific id>`.
|
|
53
|
+
* // Since the `@id` is generated in the engine, the object is
|
|
54
|
+
* // *preliminarily given a mock id* which will be replaced immediately.
|
|
55
|
+
* doc.value.expenses.push({
|
|
56
|
+
* title: "New expense",
|
|
57
|
+
* date: new Date().toISOString(),
|
|
58
|
+
* });
|
|
59
|
+
* };
|
|
60
|
+
* </script>
|
|
61
|
+
*
|
|
62
|
+
* <template>
|
|
63
|
+
* <div v-if="!doc">
|
|
64
|
+
* Loading...
|
|
65
|
+
* </div>
|
|
66
|
+
* <div v-else>
|
|
67
|
+
* <p v-if="expenses.length === 0">
|
|
68
|
+
* No expenses yet.
|
|
69
|
+
* </p>
|
|
70
|
+
* <template v-else>
|
|
71
|
+
* <button
|
|
72
|
+
* @click={() => createExpense()}
|
|
73
|
+
* >
|
|
74
|
+
* + Add expense
|
|
75
|
+
* </button>
|
|
76
|
+
* <ExpenseCard
|
|
77
|
+
* v-for="expense in expenses"
|
|
78
|
+
* :key="expense['@id']"
|
|
79
|
+
* :expense="expense"
|
|
80
|
+
* />
|
|
81
|
+
* </template>
|
|
82
|
+
* </div>
|
|
83
|
+
* </template>
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* In the `ExpenseCard` component:
|
|
87
|
+
* ```html
|
|
88
|
+
* <script lang="ts">
|
|
89
|
+
* const { expense } = defineProps<{
|
|
90
|
+
* expense: DeepSignal<Expense>;
|
|
91
|
+
* }>();
|
|
92
|
+
*
|
|
93
|
+
* // If you modify expense in the component,
|
|
94
|
+
* // the changes are immediately propagated to the other components
|
|
95
|
+
* // And persisted in the database.
|
|
96
|
+
* </script>
|
|
97
|
+
*
|
|
98
|
+
* <template>
|
|
99
|
+
* <input
|
|
100
|
+
* v-model="expense.title"
|
|
101
|
+
* placeholder="Expense title"
|
|
102
|
+
* />
|
|
103
|
+
* </template>
|
|
104
|
+
* ```
|
|
98
105
|
*/
|
|
99
106
|
export function useDiscrete(documentId) {
|
|
100
|
-
const
|
|
107
|
+
const ormSubscription = computed(() => {
|
|
101
108
|
const id = toValue(documentId);
|
|
102
|
-
return id ?
|
|
109
|
+
return id ? DiscreteOrmSubscription.getOrCreate(id) : undefined;
|
|
110
|
+
});
|
|
111
|
+
const ret = shallowReactive({
|
|
112
|
+
doc: undefined,
|
|
113
|
+
});
|
|
114
|
+
watchEffect(() => {
|
|
115
|
+
ormSubscription.value?.readyPromise.then(() => {
|
|
116
|
+
ret.doc = useDeepSignal(ormSubscription.value.signalObject);
|
|
117
|
+
});
|
|
103
118
|
});
|
|
104
119
|
onBeforeUnmount(() => {
|
|
105
|
-
|
|
120
|
+
ormSubscription.value?.close();
|
|
106
121
|
});
|
|
107
|
-
|
|
108
|
-
const state = useDeepSignal(signalSource);
|
|
109
|
-
const data = computed(() => ormConnection.value?.signalObject ? state : undefined);
|
|
110
|
-
return { data };
|
|
122
|
+
return toRefs(ret);
|
|
111
123
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Scope } from "../../types.ts";
|
|
2
2
|
import type { BaseType, ShapeType } from "@ng-org/shex-orm";
|
|
3
3
|
import { DeepSignalSet } from "@ng-org/alien-deepsignals";
|
|
4
4
|
/**
|
|
@@ -10,71 +10,65 @@ import { DeepSignalSet } from "@ng-org/alien-deepsignals";
|
|
|
10
10
|
* changes coming from the backend (or other components) cause an immediate rerender.
|
|
11
11
|
*
|
|
12
12
|
* @param shape The {@link ShapeType} the objects should have (generated by the shex-orm tool).
|
|
13
|
-
* @param scope The scope in which the objects should be.
|
|
13
|
+
* @param scope The scope in which the objects should be. Leaving it `undefined` makes no subscription.
|
|
14
14
|
* @returns A {@link DeepSignalSet} containing the objects matching the shape type and scope.
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
|
-
```html
|
|
18
|
-
<script lang="ts">
|
|
19
|
-
// Contains all expense objects with `@id` <s1 IRI> or <s2 IRI> and `@graph` <g1 IRI> or <g2 IRI>
|
|
20
|
-
const expenses: DeepSignalSet<Expense> = useShape(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const expensesSorted = computed(() => [...expenses].sort((a, b) =>
|
|
26
|
-
|
|
27
|
-
));
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
// Leave `@id` an empty string to auto-generate a subject IRI (adjust your scope accordingly).
|
|
31
|
-
|
|
32
|
-
//
|
|
33
|
-
// If it is not, use the combination of `@graph` and `@id`.
|
|
34
|
-
</script>
|
|
35
|
-
|
|
36
|
-
<template>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
</template>
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
In the `ExpenseCard` component:
|
|
53
|
-
```html
|
|
54
|
-
<script lang="ts">
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
}>();
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
<input
|
|
72
|
-
v-model="expense.title"
|
|
73
|
-
placeholder="Expense title"
|
|
74
|
-
/>
|
|
75
|
-
</template>
|
|
76
|
-
```
|
|
17
|
+
* ```html
|
|
18
|
+
* <script lang="ts">
|
|
19
|
+
* // Contains all expense objects with `@id` <s1 IRI> or <s2 IRI> and `@graph` <g1 IRI> or <g2 IRI>
|
|
20
|
+
* const expenses: DeepSignalSet<Expense> = useShape(ExpenseShapeType,
|
|
21
|
+
* {graphs: ["<g1 IRI>", "<g2 IRI>"],
|
|
22
|
+
* subjects: ["<s1 IRI>", "<s2 IRI>"]});
|
|
23
|
+
*
|
|
24
|
+
*
|
|
25
|
+
* const expensesSorted = computed(() => [...expenses].sort((a, b) =>
|
|
26
|
+
* a.dateOfPurchase.localeCompare(b.dateOfPurchase)
|
|
27
|
+
* ));
|
|
28
|
+
*
|
|
29
|
+
* // Simply call expenses.add({"@graph": "<g1 or g2 IRI>", "@id": "", title: "Example title"}), to add new elements.
|
|
30
|
+
* // Leave `@id` an empty string to auto-generate a subject IRI (adjust your scope accordingly).
|
|
31
|
+
*
|
|
32
|
+
* // Note that if you use `@id` (the subject IRI) as key, you need to ensure that it is unique within your scope.
|
|
33
|
+
* // If it is not, use the combination of `@graph` and `@id`.
|
|
34
|
+
* </script>
|
|
35
|
+
*
|
|
36
|
+
* <template>
|
|
37
|
+
* <div>
|
|
38
|
+
* <p v-if="expensesSorted.length === 0">
|
|
39
|
+
* No expenses yet.
|
|
40
|
+
* </p>
|
|
41
|
+
* <template v-else>
|
|
42
|
+
* <ExpenseCard
|
|
43
|
+
* v-for="expense in expensesSorted"
|
|
44
|
+
* :key="expense['@id'])"
|
|
45
|
+
* :expense="expense"
|
|
46
|
+
* />
|
|
47
|
+
* </template>
|
|
48
|
+
* </div>
|
|
49
|
+
* </template>
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* In the `ExpenseCard` component:
|
|
53
|
+
* ```html
|
|
54
|
+
* <script lang="ts">
|
|
55
|
+
* const { expense } = defineProps<{
|
|
56
|
+
* expense: DeepSignal<Expense>;
|
|
57
|
+
* }>();
|
|
58
|
+
*
|
|
59
|
+
* // If you modify expense in the component,
|
|
60
|
+
* // the changes are immediately propagated to the other components
|
|
61
|
+
* // And persisted in the database.
|
|
62
|
+
* </script>
|
|
63
|
+
*
|
|
64
|
+
* <template>
|
|
65
|
+
* <input
|
|
66
|
+
* v-model="expense.title"
|
|
67
|
+
* placeholder="Expense title"
|
|
68
|
+
* />
|
|
69
|
+
* </template>
|
|
70
|
+
* ```
|
|
77
71
|
*/
|
|
78
|
-
export declare function useShape<T extends BaseType>(shape: ShapeType<T>, scope
|
|
72
|
+
export declare function useShape<T extends BaseType>(shape: ShapeType<T>, scope: Scope): DeepSignalSet<T>;
|
|
79
73
|
export default useShape;
|
|
80
74
|
//# sourceMappingURL=useShape.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useShape.d.ts","sourceRoot":"","sources":["../../../src/frontendAdapters/vue/useShape.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useShape.d.ts","sourceRoot":"","sources":["../../../src/frontendAdapters/vue/useShape.ts"],"names":[],"mappings":"AAUA,OAAO,EAAkB,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAG5D,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,QAAQ,EACvC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,KAAK,oBAef;AAED,eAAe,QAAQ,CAAC"}
|