Skip to content

Commit ca88108

Browse files
committed
release v1.1.0, add get, fix odd intermittent root document error
1 parent 65a4a25 commit ca88108

15 files changed

+111
-97
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
.cache
2+
.cache
3+
example/dist

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Perge is a minimal p2p synchronization system for [Automerge](https://github.com
1313
- [`readonly docSet: Automerge.DocSet<any>;`](#readonly-docset-automergedocsetany)
1414
- [`readonly peer: Peer`](#readonly-peer-peer)
1515
- [`connect(id: string, conn?: PeerJS.DataConnection): Peer.DataConnection;`](#connectid-string-conn-peerjsdataconnection-peerdataconnection)
16+
- [`get<T>(id: string): Doc<T>`](#gettid-string-doct)
1617
- [`select<T>(id: string): (fn: Function, ...args: any[]) => Automerge.Doc<T>`](#selecttid-string-fn-function-args-any--automergedoct)
1718
- [`subscribe<T>(idOrSetHandler: string | Automerge.DocSetHandler<T>, callback?: Automerge.ChangeFn<T>): () => void`](#subscribetidorsethandler-string--automergedocsethandlert-callback-automergechangefnt---void)
1819

@@ -37,7 +38,9 @@ yarn add perge
3738

3839
## Quick Start
3940

40-
For a more complete example, see [the example page](./example/index.html)
41+
For a more complete example, see [the example page](./example/index.html).
42+
43+
You can run the example with `yarn dev:example` which uses [Parcel](https://parceljs.org/getting_started.html)
4144

4245
```js
4346
import { change } from 'automerge'
@@ -117,10 +120,14 @@ perge.peer.on('error', (err) => {
117120

118121
Connects to a `PeerJS` peer with the given ID and sends outgoing `Automerge.DocSet` syncronization messages using the `Automerge.Connection` protocol.
119122

120-
Returns
123+
Returns the DataConnection so you can register your own lifecycle callbacks.
121124

122125
Optionally, you can pass an existing `PeerJS` connection.
123126

127+
#### `get<T>(id: string): Doc<T>`
128+
129+
Gets an existing doc with given ID, or initializes a new doc with the client's actor ID.
130+
124131
#### `select<T>(id: string): (fn: Function, ...args: any[]) => Automerge.Doc<T>`
125132

126133
- [Updating Automerge Documents](https://github.com/automerge/automerge#updating-a-document)

dist/index.d.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import Peer from 'peerjs';
2-
import * as Automerge from 'automerge';
2+
import { DocSet, Doc, ChangeFn, DocSetHandler, change, undo, redo } from 'automerge';
3+
declare type AutomergeUpdateMethod = typeof change | typeof undo | typeof redo;
34
export interface PergeConfig {
45
decode?: (msg: string) => any;
56
encode?: (msg: any) => string;
67
peer?: Peer;
7-
docSet?: Automerge.DocSet<any>;
8+
docSet?: DocSet<any>;
89
}
910
export default class Perge {
1011
readonly peer: Peer;
11-
readonly docSet: Automerge.DocSet<any>;
12+
readonly docSet: DocSet<any>;
1213
private _connections;
1314
private _actorId;
1415
private _encode;
1516
private _decode;
1617
constructor(actorId: string, config?: PergeConfig);
1718
connect(id: string, conn?: Peer.DataConnection): Peer.DataConnection;
18-
select<T>(id: string): (fn: Function, ...args: any[]) => Automerge.Doc<T>;
19-
subscribe<T>(idOrSetHandler: string | Automerge.DocSetHandler<T>, callback?: Automerge.ChangeFn<T>): () => void;
19+
get<T>(id: string): Doc<T>;
20+
select<T>(id: string): (changeMethod: AutomergeUpdateMethod, ...args: any[]) => Doc<T>;
21+
subscribe<T>(idOrSetHandler: string | DocSetHandler<T>, callback?: ChangeFn<T>): () => void;
2022
}
23+
export {};

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.m.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)