@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
package/dist/index.cjs
CHANGED
|
@@ -493,6 +493,10 @@ function useStorageStatus() {
|
|
|
493
493
|
/**
|
|
494
494
|
* Open a `@crdt` field of the record `recordId()` names, for an editor to bind
|
|
495
495
|
* to (`field()?.getDoc()`). Re-opens when the id changes; closes on cleanup.
|
|
496
|
+
*
|
|
497
|
+
* The accessor stays `null` until the field is loaded (`CrdtField.isLoaded`):
|
|
498
|
+
* this device had the document, or the server answered. Until then show the
|
|
499
|
+
* column's text instead of binding an editor to a document still arriving.
|
|
496
500
|
*/
|
|
497
501
|
function useCrdtField(table, recordId, field) {
|
|
498
502
|
const db = useDb();
|
|
@@ -504,14 +508,21 @@ function useCrdtField(table, recordId, field) {
|
|
|
504
508
|
}
|
|
505
509
|
const sp00ky = db.getSp00ky();
|
|
506
510
|
let superseded = false;
|
|
511
|
+
let offLoaded = () => {};
|
|
507
512
|
sp00ky.openCrdtField(table, id, field).then((cf) => {
|
|
508
|
-
if (
|
|
509
|
-
|
|
513
|
+
if (superseded) {
|
|
514
|
+
sp00ky.closeCrdtField(table, id, field);
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
offLoaded = cf.onLoaded(() => {
|
|
518
|
+
if (!superseded) setCrdtField(cf);
|
|
519
|
+
});
|
|
510
520
|
}).catch((err) => {
|
|
511
521
|
console.error(`[useCrdtField] Failed to open CRDT field ${table}.${field} on ${id}:`, err);
|
|
512
522
|
});
|
|
513
523
|
return () => {
|
|
514
524
|
superseded = true;
|
|
525
|
+
offLoaded();
|
|
515
526
|
if (crdtField()) {
|
|
516
527
|
sp00ky.closeCrdtField(table, id, field);
|
|
517
528
|
setCrdtField(null);
|