@automerge/automerge-repo-react-hooks 0.1.4-alpha.1 → 0.2.0

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 CHANGED
@@ -7,7 +7,6 @@
7
7
  ```ts
8
8
  import React, { StrictMode } from "react"
9
9
  import ReactDOM from "react-dom/client"
10
- import localforage from "localforage"
11
10
 
12
11
  import { Repo, DocCollection } from "@automerge/automerge-repo"
13
12
 
@@ -31,24 +30,6 @@ async function getRepo(): Promise<DocCollection> {
31
30
  })
32
31
  }
33
32
 
34
- async function getRootDocument(repo: DocCollection, initFunction: any) {
35
- let docId: string | null = window.location.hash.replace(/^#/, "")
36
- if (!docId) {
37
- docId = await localforage.getItem("root")
38
- }
39
- let rootHandle
40
-
41
- if (!docId) {
42
- rootHandle = repo.create()
43
- rootHandle.change(initFunction)
44
- await localforage.setItem("root", rootHandle.documentId)
45
- } else {
46
- rootHandle = await repo.find(docId)
47
- window.location.hash = docId
48
- }
49
- return rootHandle
50
- }
51
-
52
33
  const initFunction = (d: RootDocument) => {
53
34
  d.items = []
54
35
  }
@@ -60,7 +41,7 @@ const params = new URLSearchParams(queryString)
60
41
  const hostname = params.get("host") || "automerge-storage-demo.glitch.me"
61
42
 
62
43
  getRepo().then(repo => {
63
- getRootDocument(repo, initFunction).then(rootDoc => {
44
+ useBootstrap(repo, initFunction).then(rootDoc => {
64
45
  const rootElem = document.getElementById("root")
65
46
  if (!rootElem) {
66
47
  throw new Error("The 'root' element wasn't found in the host HTML doc.")
@@ -1 +1 @@
1
- {"version":3,"file":"useDocument.d.ts","sourceRoot":"","sources":["../src/useDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,UAAU,EAAyB,MAAM,2BAA2B,CAAA;AAI7E,wBAAgB,WAAW,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,UAAU,uBAyBL,SAAS,CAAC,CAAC,KAAK,IAAI,EACpE"}
1
+ {"version":3,"file":"useDocument.d.ts","sourceRoot":"","sources":["../src/useDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAiB,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAAE,UAAU,EAAyB,MAAM,2BAA2B,CAAA;AAI7E,wBAAgB,WAAW,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,UAAU,uBAyBL,SAAS,CAAC,CAAC,KAAK,IAAI,EACpE"}
@@ -15,10 +15,10 @@ export function useDocument(documentId) {
15
15
  };
16
16
  return cleanup;
17
17
  }, [handle]);
18
- const changeDoc = (changeFn) => {
18
+ const changeDoc = (changeFn, options) => {
19
19
  if (!handle)
20
20
  return;
21
- handle.change(changeFn);
21
+ handle.change(changeFn, options);
22
22
  };
23
23
  return [doc, changeDoc];
24
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automerge/automerge-repo-react-hooks",
3
- "version": "0.1.4-alpha.1",
3
+ "version": "0.2.0",
4
4
  "description": "Hooks to access an Automerge Repo from your react app.",
5
5
  "repository": "https://github.com/automerge/automerge-repo",
6
6
  "author": "Peter van Hardenberg <pvh@pvh.ca>",
@@ -13,7 +13,7 @@
13
13
  "watch": "npm-watch"
14
14
  },
15
15
  "dependencies": {
16
- "@automerge/automerge-repo": "^0.1.4-alpha.1"
16
+ "@automerge/automerge-repo": "^0.2.0"
17
17
  },
18
18
  "watch": {
19
19
  "build": {
@@ -26,5 +26,5 @@
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
- "gitHead": "10312fcdf52f56a4834236a45f7814886cd3cc56"
29
+ "gitHead": "b17ea68dce605c06e57e4fcd6e6295ef968a8b6d"
30
30
  }
@@ -1,4 +1,4 @@
1
- import { Doc, ChangeFn } from "@automerge/automerge"
1
+ import { Doc, ChangeFn, ChangeOptions } from "@automerge/automerge"
2
2
  import { DocumentId, DocHandlePatchPayload } from "@automerge/automerge-repo"
3
3
  import { useEffect, useState } from "react"
4
4
  import { useRepo } from "./useRepo"
@@ -23,9 +23,9 @@ export function useDocument<T>(documentId?: DocumentId) {
23
23
  return cleanup
24
24
  }, [handle])
25
25
 
26
- const changeDoc = (changeFn: ChangeFn<T>) => {
26
+ const changeDoc = (changeFn: ChangeFn<T>, options?: ChangeOptions<T> | undefined) => {
27
27
  if (!handle) return
28
- handle.change(changeFn)
28
+ handle.change(changeFn, options)
29
29
  }
30
30
 
31
31
  return [doc, changeDoc] as [Doc<T>, (changeFn: ChangeFn<T>) => void]