Skip to content

Commit 9555d91

Browse files
committed
Use uppercase letters as though I were a professional
1 parent eb80852 commit 9555d91

16 files changed

+84
-77
lines changed

readme.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SolidJS primitives for Automerge Repo
22

3-
helpers for using <a href="https://automerge.org/docs/repositories/">
3+
Helpers for using <a href="https://automerge.org/docs/repositories/">
44
<img alt="" src=.assets/automerge.png width=22 height=22>
55
Automerge
66
</a> with <a href="https://www.solidjs.com/">
@@ -11,24 +11,25 @@ SolidJS
1111
> [!note]
1212
>
1313
> This library targets `@automerge/automerge-repo@2` which is currently in
14-
> Alpha.
14+
> Alpha
1515
>
1616
> Changes adapting to breaking changes will be reflected as patch bumps in this
1717
> library, until `@automerge/automerge-repo@2` is stable.
1818
1919
```sh
20+
pnpm add @automerge/automerge-repo@next
2021
pnpm add automerge-repo-solid-primitives@next
2122
```
2223

2324
## useDocument ✨
2425

25-
get a fine-grained live view of an automerge document from its URL.
26+
Get a fine-grained live view of an automerge document from its URL.
2627

27-
when the handle receives changes, it converts the incoming automerge patch ops
28+
When the handle receives changes, it converts the incoming automerge patch ops
2829
to precise solid store updates, giving you fine-grained reactivity that's
2930
consistent across space and time.
3031

31-
returns `[doc, handle]`.
32+
Returns `[doc, handle]`.
3233

3334
```ts
3435
useDocument<T>(
@@ -46,55 +47,55 @@ const inc = () => handle()?.change(d => d.count++)
4647
return <button onclick={inc}>{doc()?.count}</button>
4748
```
4849

49-
the `{repo}` option can be left out if you are using [RepoContext](#repocontext).
50+
The `{repo}` option can be left out if you are using [RepoContext](#repocontext).
5051

5152
## createDocumentProjection
5253

53-
get a fine-grained live view from a signal automerge handle.
54+
Get a fine-grained live view from a signal automerge handle.
5455

55-
underlying primitive for [`useDocument`](#usedocument-).
56+
Underlying primitive for [`useDocument`](#usedocument-).
5657

57-
works with [`useHandle`](#usehandle).
58+
Works with [`useHandle`](#usehandle).
5859

5960
```ts
6061
createDocumentProjection<T>(() => AutomergeUrl): Doc<T>
6162
```
6263

6364
```tsx
6465
// example
65-
let handle = repo.find(url)
66-
let doc = makeDeepDocumentProjection<{items: {title: string}[]}>(handle)
66+
const handle = repo.find(url)
67+
const doc = makeDocumentProjection<{items: {title: string}[]}>(handle)
6768

6869
// subscribes fine-grained to doc.items[1].title
6970
return <h1>{doc.items[1].title}</h1>
7071
```
7172

7273
## makeDocumentProjection
7374

74-
just like `useDocument`, but without a reactive input.
75+
Just like `createDocumentProjection`, but without a reactive input.
7576

76-
underlying primitive for [`createDocumentProjection`](#createdocumentprojection).
77+
Underlying primitive for [`createDocumentProjection`](#createDocumentProjection).
7778

7879
```ts
79-
makeDeepDocumentProjection<T>(handle: Handle<T>): Doc<T>
80+
makeDocumentProjection<T>(handle: Handle<T>): Doc<T>
8081
```
8182

8283
```tsx
8384
// example
84-
let handle = repo.find(url)
85-
let doc = makeDeepDocumentProjection<{items: {title: string}[]}>(handle)
85+
const handle = repo.find(url)
86+
const doc = makeDocumentProjection<{items: {title: string}[]}>(handle)
8687

8788
// subscribes fine-grained to doc.items[1].title
8889
return <h1>{doc.items[1].title}</h1>
8990
```
9091

9192
## useHandle
9293

93-
get a [handle](https://automerge.org/docs/repositories/dochandles/) from the
94+
Get a [handle](https://automerge.org/docs/repositories/dochandles/) from the
9495
repo as a
9596
[resource](https://docs.solidjs.com/reference/basic-reactivity/create-resource).
9697

97-
perfect for handing to `createDocumentProjection`.
98+
Perfect for handing to `createDocumentProjection`.
9899

99100
```ts
100101
useHandle<T>(
@@ -109,7 +110,7 @@ const handle = useHandle(id, {repo})
109110
const handle = useHandle(id)
110111
```
111112

112-
the `repo` option can be left out if you are using [RepoContext](#repocontext).
113+
The `repo` option can be left out if you are using [RepoContext](#repocontext).
113114

114115
## context
115116

src/autoproduce.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {apply, fromAutomerge} from "cabbages"
1010
* [Solid
1111
* Stores](https://docs.solidjs.com/reference/store-utilities/create-store)
1212
*/
13-
export function autoproduce<T>(patches: Patch[]) {
13+
export default function autoproduce<T>(patches: Patch[]) {
1414
return (doc: T) => {
1515
for (let patch of patches) {
1616
const [path, range, val] = fromAutomerge(patch)

src/context.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type {Repo} from "@automerge/automerge-repo"
2+
import {createContext} from "solid-js"
3+
4+
/**
5+
* a [context](https://docs.solidjs.com/concepts/context) that provides access
6+
* to an Automerge Repo. you don't need this, you can pass the repo in the
7+
* second arg to the functions that need it.
8+
*/
9+
export const RepoContext = createContext<Repo | null>(null)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {createMemo, type Accessor} from "solid-js"
22
import {DocHandle, type Doc} from "@automerge/automerge-repo"
3-
import {makeDocumentProjection} from "./make-document-projection.js"
3+
import makeDocumentProjection from "./makeDocumentProjection.js"
44
import {access} from "@solid-primitives/utils"
55

66
/**
@@ -9,7 +9,7 @@ import {access} from "@solid-primitives/utils"
99
* @param handle an accessor (signal/resource) of a
1010
* [DocHandle](https://automerge.org/automerge-repo/classes/_automerge_automerge_repo.DocHandle.html)
1111
*/
12-
export function createDocumentProjection<T>(
12+
export default function createDocumentProjection<T>(
1313
handle: Accessor<DocHandle<T> | undefined>
1414
) {
1515
const projection = createMemo<Doc<T> | undefined>(

src/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
export {autoproduce} from "./autoproduce.js"
2-
export {useDocument} from "./use-document.js"
3-
export {useHandle} from "./use-handle.js"
4-
export {makeDocumentProjection} from "./make-document-projection.js"
5-
export {createDocumentProjection} from "./create-document-projection.js"
6-
export {RepoContext, useRepo} from "./use-repo.js"
1+
export {default as autoproduce} from "./autoproduce.js"
2+
export {default as useDocument} from "./useDocument.js"
3+
export {default as useHandle} from "./useDocHandle.js"
4+
export {default as makeDocumentProjection} from "./makeDocumentProjection.js"
5+
export {default as createDocumentProjection} from "./createDocumentProjection.js"
6+
export {default as useRepo} from "./useRepo.js"
7+
export {RepoContext} from "./context.js"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {onCleanup} from "solid-js"
22
import {Doc, DocHandle, DocHandleChangePayload} from "@automerge/automerge-repo"
3-
import {autoproduce} from "./autoproduce.js"
3+
import autoproduce from "./autoproduce.js"
44
import {createStore, produce, reconcile, type Store} from "solid-js/store"
55

66
const cache = new WeakMap<
@@ -17,7 +17,7 @@ const cache = new WeakMap<
1717
* @param handle an Automerge
1818
* [DocHandle](https://automerge.org/automerge-repo/classes/_automerge_automerge_repo.DocHandle.html)
1919
*/
20-
export function makeDocumentProjection<T>(handle: DocHandle<T>) {
20+
export default function makeDocumentProjection<T>(handle: DocHandle<T>) {
2121
onCleanup(() => {
2222
const item = cache.get(handle)!
2323
if (!item) return

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {Repo} from "@automerge/automerge-repo"
22

3-
export interface UseHandleOptions {
3+
export interface UseDocHandleOptions {
44
repo?: Repo
55
// @internal
66
"~skipInitialValue"?: boolean

src/use-repo.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
} from "@automerge/automerge-repo/slim"
77
import {createEffect, createResource, useContext} from "solid-js"
88
import {access, type MaybeAccessor} from "@solid-primitives/utils"
9-
import {RepoContext} from "./use-repo.js"
10-
import type {UseHandleOptions} from "./types.js"
9+
import {RepoContext} from "./context.js"
10+
import type {UseDocHandleOptions} from "./types.js"
1111

1212
const readyStates = ["ready", "deleted", "unavailable"] as HandleState[]
1313
const badStates = ["deleted", "unavailable"] as HandleState[]
@@ -22,15 +22,16 @@ const badStates = ["deleted", "unavailable"] as HandleState[]
2222
* Waits for the handle to be
2323
* [ready](https://automerge.org/automerge-repo/variables/_automerge_automerge_repo.HandleState-1.html).
2424
*/
25-
export function useHandle<T>(
25+
export default function useDocHandle<T>(
2626
url: MaybeAccessor<AutomergeUrl | undefined>,
27-
options?: UseHandleOptions
27+
options?: UseDocHandleOptions
2828
) {
2929
const contextRepo = useContext(RepoContext)
3030

3131
if (!options?.repo && !contextRepo) {
3232
throw new Error("use outside <RepoContext> requires options.repo")
3333
}
34+
3435
const repo = (options?.repo || contextRepo)!
3536

3637
function getExistingHandle() {
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ import {
33
type Doc,
44
type DocHandle,
55
} from "@automerge/automerge-repo"
6-
import {createDocumentProjection} from "./create-document-projection.js"
6+
import createDocumentProjection from "./createDocumentProjection.js"
77
import type {MaybeAccessor} from "@solid-primitives/utils"
8-
import {useHandle} from "./use-handle.js"
9-
import type {UseHandleOptions} from "./types.js"
8+
import useDocHandle from "./useDocHandle.js"
9+
import type {UseDocHandleOptions} from "./types.js"
1010
import type {Accessor, Resource} from "solid-js"
1111

1212
/**
1313
* get a fine-grained live view of a document, and its handle, from a URL.
1414
* @param url a function that returns a url
1515
*/
16-
export function useDocument<T>(
16+
export default function useDoc<T>(
1717
url: MaybeAccessor<AutomergeUrl | undefined>,
18-
options?: UseHandleOptions
18+
options?: UseDocHandleOptions
1919
): [Accessor<Doc<T> | undefined>, Resource<DocHandle<T> | undefined>] {
20-
const handle = useHandle<T>(url, options)
20+
const handle = useDocHandle<T>(url, options)
2121
return [createDocumentProjection<T>(handle), handle] as const
2222
}

0 commit comments

Comments
 (0)