Helpers for using Automerge with SolidJS .
A convenience context for Automerge-Repo Solid apps. Optional: if you prefer you
can pass a repo as an option to useHandle
or useDocument
.
<RepoContext.Provider repo={Repo}>
<App />
</RepoContext.Provider>
Get the repo from the context.
useRepo(): Repo
let repo = useRepo()
Get a handle from the repo as a resource.
useHandle<T>(
() => AnyDocumentId,
options?: {repo: Repo}
): Resource<Handle<T>>
let handle = useHandle(id)
// or
let handle = useHandle(id, {repo})
The repo
option can be left out if you are using RepoContext.
Get a document and change function from the repo as a resource.
useDocument<T>(
() => AnyDocumentId,
options?: {repo: Repo}
): [Resource<T>, (fn: changeFn<T>) => void]
let [doc, change] = useDocument(id)
// or
let [doc, change] = useDocument(id, {repo})
The repo
option can be left out if you are using RepoContext.
Create a store for a handle's document. It's subscribed to the handle's changes, and converts incoming automerge operations to store updates, providing fine-grained reactivity that's consistent across space and time.
createDocumentStore<T>(
() => Handle<T>
): Resource<Doc<T>>
let handle = useHandle(id, {repo})
let doc = createDocumentStore(handle)
return <h1>{doc.items[1].title}</h1>