automerge-repo-solid-primitives
v1.1.3
Published
automerge-repo primitives for your solidjs app
Downloads
7
Readme
Solid Primitives for Automerge Repo
Helpers for using Automerge with SolidJS .
RepoContext
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>
useRepo
Get the repo from the context.
useRepo(): Repo
e.g.
let repo = useRepo()
useHandle
Get a handle from the repo as a resource.
useHandle<T>(
() => AnyDocumentId,
options?: {repo: Repo}
): Resource<Handle<T>>
e.g.
let handle = useHandle(id)
// or
let handle = useHandle(id, {repo})
The repo
option can be left out if you are using RepoContext.
useDocument
Get a document and change function from the repo as a resource.
useDocument<T>(
() => AnyDocumentId,
options?: {repo: Repo}
): [Resource<T>, (fn: changeFn<T>) => void]
e.g.
let [doc, change] = useDocument(id)
// or
let [doc, change] = useDocument(id, {repo})
The repo
option can be left out if you are using RepoContext.
createDocumentStore
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>>
e.g.
let handle = useHandle(id, {repo})
let doc = createDocumentStore(handle)
return <h1>{doc.items[1].title}</h1>