@automerge/automerge-repo-solid-primitives 2.5.4 → 2.5.5

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.
@@ -0,0 +1,10 @@
1
+ import { Accessor } from 'solid-js';
2
+ import { Doc, DocHandle } from '@automerge/automerge-repo/slim';
3
+
4
+ /**
5
+ * a light coarse-grained primitive when you care only _that_ a doc has changed,
6
+ * and not _how_. works with {@link useDocHandle}.
7
+ * @param handle an accessor (signal/resource) of a
8
+ * [DocHandle](https://automerge.org/automerge-repo/classes/_automerge_automerge_repo.DocHandle.html)
9
+ */
10
+ export default function createDocSignal<T extends object>(handle: Accessor<DocHandle<T> | undefined>): Accessor<Doc<T> | undefined>;
package/dist/index.d.ts CHANGED
@@ -3,5 +3,8 @@ export { default as useDocument } from './useDocument.js';
3
3
  export { default as useDocHandle } from './useDocHandle.js';
4
4
  export { default as makeDocumentProjection } from './makeDocumentProjection.js';
5
5
  export { default as createDocumentProjection } from './createDocumentProjection.js';
6
+ export { default as makeDocSignal } from './makeDocSignal.js';
7
+ export { default as createDocSignal } from './createDocSignal.js';
8
+ export { default as useDocSignal } from './useDocSignal.js';
6
9
  export { default as useRepo } from './useRepo.js';
7
10
  export { RepoContext } from './context.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { onCleanup, createMemo, createContext, useContext, createResource, createEffect } from 'solid-js';
1
+ import { onCleanup, createMemo, createContext, useContext, createResource, createEffect, createSignal } from 'solid-js';
2
2
  import { createStore, produce, reconcile } from 'solid-js/store';
3
3
 
4
4
  // Properties of the document root object
@@ -1469,11 +1469,42 @@ function useDocument(url, options) {
1469
1469
  return [createDocumentProjection(handle), handle];
1470
1470
  }
1471
1471
 
1472
+ function makeDocSignal(handle) {
1473
+ const [signal, setSignal] = createSignal(handle.doc());
1474
+ function update() {
1475
+ setSignal(() => handle.doc());
1476
+ }
1477
+ handle.on("change", update);
1478
+ onCleanup(() => handle.off("change", update));
1479
+ return signal;
1480
+ }
1481
+
1482
+ function createDocSignal(handle) {
1483
+ const [signal, setSignal] = createSignal(handle()?.doc());
1484
+ createEffect(() => {
1485
+ const h = handle();
1486
+ function update() {
1487
+ setSignal(() => h?.doc());
1488
+ }
1489
+ update();
1490
+ if (h) {
1491
+ h.on("change", update);
1492
+ onCleanup(() => h.off("change", update));
1493
+ }
1494
+ });
1495
+ return signal;
1496
+ }
1497
+
1498
+ function useDocSignal(url, options) {
1499
+ const handle = useDocHandle(url, options);
1500
+ return [createDocSignal(handle), handle];
1501
+ }
1502
+
1472
1503
  function useRepo() {
1473
1504
  const repo = useContext(RepoContext);
1474
1505
  if (!repo) throw new Error("Please wrap me in a <RepoContext value={repo}>");
1475
1506
  return repo;
1476
1507
  }
1477
1508
 
1478
- export { RepoContext, autoproduce, createDocumentProjection, makeDocumentProjection, useDocHandle, useDocument, useRepo };
1509
+ export { RepoContext, autoproduce, createDocSignal, createDocumentProjection, makeDocSignal, makeDocumentProjection, useDocHandle, useDocSignal, useDocument, useRepo };
1479
1510
  //# sourceMappingURL=index.js.map