@spooky-sync/client-solid2 0.0.1-canary.328 → 0.0.1-canary.330
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/dist/index.cjs +13 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/lib/use-crdt-field.ts +13 -3
|
@@ -5,6 +5,10 @@ import type { CrdtField } from '@spooky-sync/core';
|
|
|
5
5
|
/**
|
|
6
6
|
* Open a `@crdt` field of the record `recordId()` names, for an editor to bind
|
|
7
7
|
* to (`field()?.getDoc()`). Re-opens when the id changes; closes on cleanup.
|
|
8
|
+
*
|
|
9
|
+
* The accessor stays `null` until the field is loaded (`CrdtField.isLoaded`):
|
|
10
|
+
* this device had the document, or the server answered. Until then show the
|
|
11
|
+
* column's text instead of binding an editor to a document still arriving.
|
|
8
12
|
*/
|
|
9
13
|
export function useCrdtField(
|
|
10
14
|
table: string,
|
|
@@ -27,14 +31,19 @@ export function useCrdtField(
|
|
|
27
31
|
}
|
|
28
32
|
const sp00ky = db.getSp00ky();
|
|
29
33
|
let superseded = false;
|
|
34
|
+
let offLoaded = () => {};
|
|
30
35
|
sp00ky
|
|
31
36
|
.openCrdtField(table, id, field)
|
|
32
37
|
.then((cf) => {
|
|
33
|
-
if (
|
|
34
|
-
setCrdtField(cf);
|
|
35
|
-
} else {
|
|
38
|
+
if (superseded) {
|
|
36
39
|
sp00ky.closeCrdtField(table, id, field);
|
|
40
|
+
return;
|
|
37
41
|
}
|
|
42
|
+
// Handed out once loaded (`CrdtField.isLoaded`): an empty document
|
|
43
|
+
// before the server answered is "not arrived yet", not "empty".
|
|
44
|
+
offLoaded = cf.onLoaded(() => {
|
|
45
|
+
if (!superseded) setCrdtField(cf);
|
|
46
|
+
});
|
|
38
47
|
})
|
|
39
48
|
.catch((err) => {
|
|
40
49
|
// Silent rejections here leave the consumer's `Show when={field()}`
|
|
@@ -47,6 +56,7 @@ export function useCrdtField(
|
|
|
47
56
|
});
|
|
48
57
|
return () => {
|
|
49
58
|
superseded = true;
|
|
59
|
+
offLoaded();
|
|
50
60
|
if (crdtField()) {
|
|
51
61
|
sp00ky.closeCrdtField(table, id, field);
|
|
52
62
|
setCrdtField(null);
|