Skip to content

Commit

Permalink
satisfy prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
pvh committed May 6, 2024
1 parent f7defd9 commit 17a8dc0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
19 changes: 9 additions & 10 deletions packages/automerge-repo-react-hooks/src/useDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ export function useDocument<T>(
// This avoids problem with out-of-order loads when the handle is changing faster
// than documents are loading.
if (handleRef.current !== handle) return
setDoc(v)
setDoc(v)
})
.catch(e => console.error(e))

const onChange = (h: DocHandleChangePayload<T>) =>
setDoc(h.doc)
const onChange = (h: DocHandleChangePayload<T>) => setDoc(h.doc)
handle.on("change", onChange)
const onDelete = () => setDoc(undefined)
handle.on("delete", onDelete)
Expand All @@ -67,13 +66,13 @@ export function useDocument<T>(
return cleanup
}, [id, handle])

const changeDoc = useCallback((
changeFn: ChangeFn<T>,
options?: ChangeOptions<T> | undefined
) => {
if (!handle) return
handle.change(changeFn, options)
}, [handle])
const changeDoc = useCallback(
(changeFn: ChangeFn<T>, options?: ChangeOptions<T> | undefined) => {
if (!handle) return
handle.change(changeFn, options)
},
[handle]
)

return [handle?.docSync(), changeDoc] as const
}
7 changes: 2 additions & 5 deletions packages/automerge-repo-react-hooks/src/useHandle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
AnyDocumentId,
DocHandle,
} from "@automerge/automerge-repo"
import { AnyDocumentId, DocHandle } from "@automerge/automerge-repo"
import { useRepo } from "./useRepo.js"

/** A hook which returns a {@link DocHandle} identified by a URL.
Expand All @@ -10,5 +7,5 @@ import { useRepo } from "./useRepo.js"
* This requires a {@link RepoContext} to be provided by a parent component.
*/
export function useHandle<T>(id?: AnyDocumentId): DocHandle<T> | undefined {
return (id ? useRepo().find(id) : undefined)
return id ? useRepo().find(id) : undefined
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ describe("useDocument", () => {
handleSlow.change(doc => (doc.foo = "slow"))
const oldDoc = handleSlow.doc.bind(handleSlow)
let loaded = false
const delay = new Promise(resolve => setTimeout(() => { loaded = true; resolve(true) }, SLOW_DOC_LOAD_TIME_MS))
const delay = new Promise(resolve =>
setTimeout(() => {
loaded = true
resolve(true)
}, SLOW_DOC_LOAD_TIME_MS)
)
handleSlow.doc = async () => {
await delay
const result = await oldDoc()
Expand Down

0 comments on commit 17a8dc0

Please sign in to comment.