@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,85 +1,94 @@
|
|
|
1
|
-
import { UseDeepSignalResult } from "@ng-org/alien-deepsignals/svelte";
|
|
2
1
|
import { DiscreteRootArray, DiscreteRootObject } from "../../types.ts";
|
|
3
2
|
/**
|
|
4
|
-
* Svelte
|
|
3
|
+
* Svelte 5 hook to subscribe to existing discrete (JSON) CRDT documents.
|
|
5
4
|
* You can modify the returned object like any other JSON object. Changes are immediately
|
|
6
5
|
* reflected in the CRDT.
|
|
7
6
|
*
|
|
8
7
|
* Establishes a 2-way binding: Modifications to the object are immediately committed,
|
|
9
|
-
* changes coming from the
|
|
8
|
+
* changes coming from the engine (or other components) cause an immediate rerender.
|
|
10
9
|
*
|
|
11
|
-
* In comparison to
|
|
10
|
+
* In comparison to {@link svelteUseShape}, discrete CRDTs are untyped.
|
|
12
11
|
* You can put any JSON data inside and need to validate the schema yourself.
|
|
13
12
|
*
|
|
14
|
-
* @param
|
|
13
|
+
* @param documentIdOrPromise The IRI of the CRDT document or a promise to that.
|
|
15
14
|
* @returns The reactive JSON object of the CRDT document.
|
|
16
15
|
*
|
|
17
16
|
*@example
|
|
18
|
-
```svelte
|
|
19
|
-
<script lang="ts">
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
17
|
+
* ```svelte
|
|
18
|
+
* <script lang="ts">
|
|
19
|
+
* // We assume you have created a CRDT document already, as below.
|
|
20
|
+
* // const documentId = await ng.doc_create(
|
|
21
|
+
* // session_id,
|
|
22
|
+
* // crdt, // "Automerge" | "YMap" | "YArray"
|
|
23
|
+
* // crdt === "Automerge" ? "data:json" : crdt === "YMap ? "data:map" : "data:array",
|
|
24
|
+
* // "store",
|
|
25
|
+
* // undefined,
|
|
26
|
+
* // );
|
|
27
|
+
*
|
|
28
|
+
* const { doc } = useDiscrete(documentIdPromise);
|
|
29
|
+
*
|
|
30
|
+
* $effect(() => {
|
|
31
|
+
* // If the CRDT document is still empty, we need to initialize it.
|
|
32
|
+
* if (doc && !doc.expenses) {
|
|
33
|
+
* doc.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
|
+
* expenses.push({
|
|
46
|
+
* title: "New expense",
|
|
47
|
+
* date: new Date().toISOString(),
|
|
48
|
+
* });
|
|
49
|
+
* };
|
|
50
|
+
*
|
|
51
|
+
*
|
|
52
|
+
* </script>
|
|
53
|
+
*
|
|
54
|
+
* <section>
|
|
55
|
+
* <div>
|
|
56
|
+
* <button on:click={() => createExpense({})}/>
|
|
57
|
+
*
|
|
58
|
+
* {#if !doc}
|
|
59
|
+
* Loading...
|
|
60
|
+
* {:else if doc.expenses.length === 0}
|
|
61
|
+
* <p>
|
|
62
|
+
* Nothing tracked yet - log your first purchase to kick things off.
|
|
63
|
+
* </p>
|
|
64
|
+
* {:else}
|
|
65
|
+
* {#each doc.expenses as expense, index (expense['@id']) }
|
|
66
|
+
* <ExpenseCard
|
|
67
|
+
* expense={expense}
|
|
68
|
+
* />
|
|
69
|
+
* {/each}
|
|
70
|
+
* {/if}
|
|
71
|
+
* </div>
|
|
72
|
+
* </section>
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* ---
|
|
76
|
+
* In the ExpenseCard component:
|
|
77
|
+
* ```svelte
|
|
78
|
+
* let {
|
|
79
|
+
* expense = $bindable(),
|
|
80
|
+
* }: { expense: Expense; } = $props();
|
|
81
|
+
* </script>
|
|
82
|
+
*
|
|
83
|
+
* <div>
|
|
84
|
+
* <input
|
|
85
|
+
* value={expense.title ?? ""}
|
|
86
|
+
* oninput={(event) => {expense.title = event.currentTarget?.value ?? ""}}
|
|
87
|
+
* />
|
|
88
|
+
* </div>
|
|
89
|
+
* ```
|
|
83
90
|
*/
|
|
84
|
-
export declare function useDiscrete(documentIdOrPromise: string | Promise<string>):
|
|
91
|
+
export declare function useDiscrete(documentIdOrPromise: string | Promise<string>): {
|
|
92
|
+
doc: DiscreteRootArray | DiscreteRootObject | undefined;
|
|
93
|
+
};
|
|
85
94
|
//# sourceMappingURL=useDiscrete.svelte.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDiscrete.svelte.d.ts","sourceRoot":"","sources":["../../../src/frontendAdapters/svelte/useDiscrete.svelte.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDiscrete.svelte.d.ts","sourceRoot":"","sources":["../../../src/frontendAdapters/svelte/useDiscrete.svelte.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwFG;AACH,wBAAgB,WAAW,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG;IACxE,GAAG,EAAE,iBAAiB,GAAG,kBAAkB,GAAG,SAAS,CAAC;CAC3D,CAwCA"}
|
|
@@ -8,117 +8,128 @@
|
|
|
8
8
|
// according to those terms.
|
|
9
9
|
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
10
10
|
import { onDestroy } from "svelte";
|
|
11
|
-
import { useDeepSignal
|
|
12
|
-
import {
|
|
11
|
+
import { useDeepSignal } from "@ng-org/alien-deepsignals/svelte";
|
|
12
|
+
import { DiscreteOrmSubscription } from "../../connector/discrete/discreteOrmSubscriptionHandler.js";
|
|
13
13
|
/**
|
|
14
|
-
* Svelte
|
|
14
|
+
* Svelte 5 hook to subscribe to existing discrete (JSON) CRDT documents.
|
|
15
15
|
* You can modify the returned object like any other JSON object. Changes are immediately
|
|
16
16
|
* reflected in the CRDT.
|
|
17
17
|
*
|
|
18
18
|
* Establishes a 2-way binding: Modifications to the object are immediately committed,
|
|
19
|
-
* changes coming from the
|
|
19
|
+
* changes coming from the engine (or other components) cause an immediate rerender.
|
|
20
20
|
*
|
|
21
|
-
* In comparison to
|
|
21
|
+
* In comparison to {@link svelteUseShape}, discrete CRDTs are untyped.
|
|
22
22
|
* You can put any JSON data inside and need to validate the schema yourself.
|
|
23
23
|
*
|
|
24
|
-
* @param
|
|
24
|
+
* @param documentIdOrPromise The IRI of the CRDT document or a promise to that.
|
|
25
25
|
* @returns The reactive JSON object of the CRDT document.
|
|
26
26
|
*
|
|
27
27
|
*@example
|
|
28
|
-
```svelte
|
|
29
|
-
<script lang="ts">
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
28
|
+
* ```svelte
|
|
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
|
+
*
|
|
39
|
+
* const { doc } = useDiscrete(documentIdPromise);
|
|
40
|
+
*
|
|
41
|
+
* $effect(() => {
|
|
42
|
+
* // If the CRDT document is still empty, we need to initialize it.
|
|
43
|
+
* if (doc && !doc.expenses) {
|
|
44
|
+
* doc.expenses = [];
|
|
45
|
+
* }
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* const createExpense = () => {
|
|
49
|
+
* // Note that we use *expense["@id"]* as a key in the expense list.
|
|
50
|
+
* // Every object added to a CRDT array gets a stable `@id` property assigned
|
|
51
|
+
* // which you can use for referencing objects in arrays even as
|
|
52
|
+
* // objects are removed or added from the array.
|
|
53
|
+
* // The `@id` is an IRI with the schema `<documentId>:d:<object-specific id>`.
|
|
54
|
+
* // Since the `@id` is generated in the engine, the object is
|
|
55
|
+
* // *preliminarily given a mock id* which will be replaced immediately.
|
|
56
|
+
* expenses.push({
|
|
57
|
+
* title: "New expense",
|
|
58
|
+
* date: new Date().toISOString(),
|
|
59
|
+
* });
|
|
60
|
+
* };
|
|
61
|
+
*
|
|
62
|
+
*
|
|
63
|
+
* </script>
|
|
64
|
+
*
|
|
65
|
+
* <section>
|
|
66
|
+
* <div>
|
|
67
|
+
* <button on:click={() => createExpense({})}/>
|
|
68
|
+
*
|
|
69
|
+
* {#if !doc}
|
|
70
|
+
* Loading...
|
|
71
|
+
* {:else if doc.expenses.length === 0}
|
|
72
|
+
* <p>
|
|
73
|
+
* Nothing tracked yet - log your first purchase to kick things off.
|
|
74
|
+
* </p>
|
|
75
|
+
* {:else}
|
|
76
|
+
* {#each doc.expenses as expense, index (expense['@id']) }
|
|
77
|
+
* <ExpenseCard
|
|
78
|
+
* expense={expense}
|
|
79
|
+
* />
|
|
80
|
+
* {/each}
|
|
81
|
+
* {/if}
|
|
82
|
+
* </div>
|
|
83
|
+
* </section>
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* ---
|
|
87
|
+
* In the ExpenseCard component:
|
|
88
|
+
* ```svelte
|
|
89
|
+
* let {
|
|
90
|
+
* expense = $bindable(),
|
|
91
|
+
* }: { expense: Expense; } = $props();
|
|
92
|
+
* </script>
|
|
93
|
+
*
|
|
94
|
+
* <div>
|
|
95
|
+
* <input
|
|
96
|
+
* value={expense.title ?? ""}
|
|
97
|
+
* oninput={(event) => {expense.title = event.currentTarget?.value ?? ""}}
|
|
98
|
+
* />
|
|
99
|
+
* </div>
|
|
100
|
+
* ```
|
|
93
101
|
*/
|
|
94
102
|
export function useDiscrete(documentIdOrPromise) {
|
|
95
103
|
let connection;
|
|
96
104
|
let isDestroyed = false;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
let doc = $state.raw(undefined);
|
|
106
|
+
const init = (docId) => {
|
|
107
|
+
if (isDestroyed)
|
|
108
|
+
return;
|
|
109
|
+
connection = DiscreteOrmSubscription.getOrCreate(docId);
|
|
110
|
+
connection.readyPromise.then(() => {
|
|
111
|
+
if (isDestroyed) {
|
|
112
|
+
connection?.close();
|
|
100
113
|
return;
|
|
101
|
-
|
|
102
|
-
connection.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
init(documentIdOrPromise);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
documentIdOrPromise.then(init);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
114
|
+
}
|
|
115
|
+
doc = useDeepSignal(connection.signalObject);
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
if (typeof documentIdOrPromise === "string") {
|
|
119
|
+
init(documentIdOrPromise);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
documentIdOrPromise.then(init);
|
|
123
|
+
}
|
|
117
124
|
onDestroy(() => {
|
|
118
125
|
isDestroyed = true;
|
|
119
126
|
if (connection) {
|
|
120
127
|
connection.close();
|
|
121
128
|
}
|
|
122
129
|
});
|
|
123
|
-
return
|
|
130
|
+
return {
|
|
131
|
+
get doc() {
|
|
132
|
+
return doc;
|
|
133
|
+
},
|
|
134
|
+
};
|
|
124
135
|
}
|
|
@@ -1,76 +1,82 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Scope } from "../../types.ts";
|
|
2
2
|
import type { BaseType, ShapeType } from "@ng-org/shex-orm";
|
|
3
|
-
import {
|
|
4
|
-
export type { UseDeepSignalResult } from "@ng-org/alien-deepsignals/svelte";
|
|
5
|
-
/** Extended result including the originating root signal wrapper from shape logic. */
|
|
6
|
-
export interface UseShapeRuneResult<T extends object> extends UseDeepSignalResult<T> {
|
|
7
|
-
root: any;
|
|
8
|
-
}
|
|
3
|
+
import { DeepSignalSet } from "@ng-org/alien-deepsignals";
|
|
9
4
|
/**
|
|
10
|
-
*
|
|
5
|
+
* Svelte 5 hook to subscribe to RDF data in the graph database using a shape, see {@link ShapeType}.
|
|
11
6
|
*
|
|
12
|
-
* Returns a {@link DeepSignalSet}
|
|
7
|
+
* Returns a {@link DeepSignalSet} that contain the objects matching the shape and that are within the scope.
|
|
13
8
|
* Establishes a 2-way binding: Modifications to the object are immediately committed,
|
|
14
|
-
* changes coming from the
|
|
9
|
+
* changes coming from the engine (or other components) cause an immediate rerender.
|
|
15
10
|
*
|
|
16
|
-
* @param shape The {@link ShapeType} the objects should have (generated by the shex-orm tool).
|
|
11
|
+
* @param shape The {@link ShapeType} the objects should have (generated by the `@ng-org/shex-orm` tool).
|
|
17
12
|
* @param scope The {@link Scope} in which the objects should be.
|
|
18
13
|
* @returns A {@link DeepSignalSet} containing the objects matching the shape type and scope.
|
|
19
14
|
*
|
|
20
15
|
* @example
|
|
21
|
-
```svelte
|
|
22
|
-
<script lang="ts">
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
16
|
+
* ```svelte
|
|
17
|
+
* <script lang="ts">
|
|
18
|
+
* // Gets all expense objects with `@id` <s1 IRI> or <s2 IRI> and `@graph` <g1 IRI> or <g2 IRI>
|
|
19
|
+
* const expenses: DeepSignalSet<Expense> = useShape(ExpenseShapeType,
|
|
20
|
+
* {graphs: ["<g1 IRI>", "<g2 IRI>"],
|
|
21
|
+
* subjects: ["<s1 IRI>", "<s2 IRI>"]});
|
|
22
|
+
*
|
|
23
|
+
* const expensesSorted = computed(() => expenses.sort((a, b) =>
|
|
24
|
+
* a.dateOfPurchase.localeCompare(b.dateOfPurchase)
|
|
25
|
+
* ));
|
|
26
|
+
*
|
|
27
|
+
* const createExpense = () => {
|
|
28
|
+
* expenses.add({
|
|
29
|
+
* "@graph": `<graph IRI>`,
|
|
30
|
+
* "@type": "http://example.org/Expense",
|
|
31
|
+
* "@id": "", // Assigns id automatically, if set to "".
|
|
32
|
+
* title: "New expense",
|
|
33
|
+
* dateOfPurchase: obj.dateOfPurchase ?? new Date().toISOString(),
|
|
34
|
+
* });
|
|
35
|
+
* };
|
|
36
|
+
*
|
|
37
|
+
*
|
|
38
|
+
* // Note that if you use `@id` (the subject IRI) as key, you need to ensure that it is unique within your scope.
|
|
39
|
+
* // If it is not, use the combination of `@graph` and `@id`.
|
|
40
|
+
* </script>
|
|
41
|
+
*
|
|
42
|
+
* <section>
|
|
43
|
+
* <div>
|
|
44
|
+
* <button on:click={() => createExpense()}>
|
|
45
|
+
* + Add expense
|
|
46
|
+
* </button>
|
|
47
|
+
*
|
|
48
|
+
* {# if expensesSorted.length === 0}
|
|
49
|
+
* <p>
|
|
50
|
+
* No expense yet.
|
|
51
|
+
* </p>
|
|
52
|
+
* {:else}
|
|
53
|
+
* {#each expensesSorted as expense, index (expense['@id']) }
|
|
54
|
+
* <ExpenseCard
|
|
55
|
+
* expense={expense}
|
|
56
|
+
* />
|
|
57
|
+
* {/each}
|
|
58
|
+
* {/if}
|
|
59
|
+
* </div>
|
|
60
|
+
* </section>
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* ---
|
|
64
|
+
* In the ExpenseCard component:
|
|
65
|
+
* ```svelte
|
|
66
|
+
* <script lang="ts">
|
|
67
|
+
* let {
|
|
68
|
+
* expense,
|
|
69
|
+
* }: { expense: DeepSignal<Expense>; } = $props();
|
|
70
|
+
* </script>
|
|
71
|
+
*
|
|
72
|
+
* <div>
|
|
73
|
+
* <input
|
|
74
|
+
* value={expense.title ?? ""}
|
|
75
|
+
* oninput={(event) => {expense.title = event.currentTarget.value}}
|
|
76
|
+
* />
|
|
77
|
+
* </div>
|
|
78
|
+
* ```
|
|
73
79
|
*/
|
|
74
|
-
export declare function useShape<T extends BaseType>(shape: ShapeType<T>, scope
|
|
80
|
+
export declare function useShape<T extends BaseType>(shape: ShapeType<T>, scope: Scope): DeepSignalSet<T>;
|
|
75
81
|
export default useShape;
|
|
76
82
|
//# sourceMappingURL=useShape.svelte.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useShape.svelte.d.ts","sourceRoot":"","sources":["../../../src/frontendAdapters/svelte/useShape.svelte.ts"],"names":[],"mappings":"AAUA,OAAO,
|
|
1
|
+
{"version":3,"file":"useShape.svelte.d.ts","sourceRoot":"","sources":["../../../src/frontendAdapters/svelte/useShape.svelte.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAI1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,QAAQ,EACvC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,KAAK,GACb,aAAa,CAAC,CAAC,CAAC,CAUlB;AAED,eAAe,QAAQ,CAAC"}
|