Skip to content

Commit

Permalink
export datatype classes, update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pvh committed Apr 23, 2024
1 parent fa2e5c0 commit 3b83c8d
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
23 changes: 13 additions & 10 deletions examples/svelte-counter/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<script lang="ts">
import svelteLogo from "./assets/svelte.svg"
import automergeLogo from "/automerge-logo.svg"
import { next as automerge } from "@automerge/automerge"
import Counter from "./lib/Counter.svelte"
import type { DocType } from "./lib/doc-type"
import { Repo, isValidAutomergeUrl } from "@automerge/automerge-repo"
import {
Counter as AutomergeCounter,
Repo,
isValidAutomergeUrl,
} from "@automerge/automerge-repo"
import { BroadcastChannelNetworkAdapter } from "@automerge/automerge-repo-network-broadcastchannel"
import { IndexedDBStorageAdapter } from "@automerge/automerge-repo-storage-indexeddb"
import { BrowserWebSocketClientAdapter } from "@automerge/automerge-repo-network-websocket"
Expand All @@ -21,15 +24,15 @@
setContextRepo(repo)
const rootDocUrl = `${document.location.hash.substring(1)}`
let handle
if (isValidAutomergeUrl(rootDocUrl)) {
handle = repo.find(rootDocUrl)
} else {
handle = repo.create<DocType>({ count: new automerge.Counter() })
}
const rootDocUrl = `${document.location.hash.substring(1)}`
let handle
if (isValidAutomergeUrl(rootDocUrl)) {
handle = repo.find(rootDocUrl)
} else {
handle = repo.create<DocType>({ count: new AutomergeCounter() })
}
const docUrl = (document.location.hash = handle.url)
const docUrl = (document.location.hash = handle.url)
</script>

<main>
Expand Down
8 changes: 4 additions & 4 deletions examples/svelte-counter/src/lib/Counter.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script lang="ts">
import {document} from "@automerge/automerge-repo-svelte-store"
import {type AutomergeUrl} from "@automerge/automerge-repo"
import type {DocType} from "./doc-type"
import { document } from "@automerge/automerge-repo-svelte-store"
import { type AutomergeUrl } from "@automerge/automerge-repo"
import type { DocType } from "./doc-type"
export let documentUrl: AutomergeUrl
const doc = document <DocType> (documentUrl)
const doc = document<DocType>(documentUrl)
const increment = () => {
doc.change(d => {
d.count.increment(1)
Expand Down
2 changes: 1 addition & 1 deletion examples/svelte-counter/src/lib/doc-type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Counter } from "@automerge/automerge"
import type { Counter } from "@automerge/automerge-repo"

export type DocType = {
count: Counter
Expand Down
2 changes: 1 addition & 1 deletion packages/automerge-repo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@automerge/automerge-repo",
"version": "1.1.8",
"version": "1.1.9",
"description": "A repository object to manage a collection of automerge documents",
"repository": "https://github.com/automerge/automerge-repo/tree/master/packages/automerge-repo",
"author": "Peter van Hardenberg <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion packages/automerge-repo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export type {
export * from "./types.js"

// export commonly used data types
export type { Counter, RawString, Cursor } from "@automerge/automerge/next"
export { Counter, RawString, Cursor } from "@automerge/automerge/next"

// export some automerge API types
export type {
Expand Down
1 change: 0 additions & 1 deletion packages/create-repo-node-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function createIndexJs(projectName: string) {
const indexJsContent = `import { Repo } from "@automerge/automerge-repo"
import { BrowserWebSocketClientAdapter } from "@automerge/automerge-repo-network-websocket"
import { NodeFSStorageAdapter } from "@automerge/automerge-repo-storage-nodefs"
import { next as Automerge } from "@automerge/automerge"
const repo = new Repo({
storage: new NodeFSStorageAdapter("./db"),
Expand Down
5 changes: 2 additions & 3 deletions packages/create-vite-app/template/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import automergeLogo from "./assets/automerge.png"
import "./App.css"
import { AutomergeUrl } from "@automerge/automerge-repo"
import { AutomergeUrl, Counter } from "@automerge/automerge-repo"
import { useDocument } from "@automerge/automerge-repo-react-hooks"
import { next as A } from "@automerge/automerge"

interface CounterDoc {
counter: A.Counter
counter: Counter
}

function App({ docUrl }: { docUrl: AutomergeUrl }) {
Expand Down
7 changes: 3 additions & 4 deletions packages/create-vite-app/template/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { isValidAutomergeUrl, Repo } from "@automerge/automerge-repo"
import { isValidAutomergeUrl, Repo, Counter } from "@automerge/automerge-repo"
import { BrowserWebSocketClientAdapter } from "@automerge/automerge-repo-network-websocket"
import { BroadcastChannelNetworkAdapter } from "@automerge/automerge-repo-network-broadcastchannel"
import { IndexedDBStorageAdapter } from "@automerge/automerge-repo-storage-indexeddb"
import { RepoContext } from "@automerge/automerge-repo-react-hooks"
import { next as A } from "@automerge/automerge" //why `next`? See the the "next" section of the conceptual overview
import React from "react"
import ReactDOM from "react-dom/client"
import App from "./App.tsx"
Expand All @@ -22,8 +21,8 @@ let handle
if (isValidAutomergeUrl(rootDocUrl)) {
handle = repo.find(rootDocUrl)
} else {
handle = repo.create<{ counter?: A.Counter }>()
handle.change(d => (d.counter = new A.Counter()))
handle = repo.create<{ counter?: Counter }>()
handle.change(d => (d.counter = new Counter()))
}
const docUrl = (document.location.hash = handle.url)
// @ts-expect-error -- we put the handle and the repo on window so you can experiment with them from the dev tools
Expand Down

0 comments on commit 3b83c8d

Please sign in to comment.