@automerge/automerge-repo-svelte-store 0.2.1 → 1.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import type { Doc, ChangeFn } from "@automerge/automerge";
2
- import { Repo, DocumentId } from "@automerge/automerge-repo";
1
+ /// <reference types="svelte" />
2
+ import type { ChangeFn, Doc } from "@automerge/automerge";
3
+ import { AutomergeUrl, Repo } from "@automerge/automerge-repo";
3
4
  export declare function getContextRepo(): Repo;
4
5
  export declare function setContextRepo(repo: Repo): void;
5
- export declare function document<T>(documentId: DocumentId): {
6
- subscribe: (this: void, run: import("svelte/store").Subscriber<Doc<T>>, invalidate?: (value?: Doc<T>) => void) => import("svelte/store").Unsubscriber;
6
+ export declare function document<T>(documentId: AutomergeUrl): {
7
+ subscribe: (this: void, run: import("svelte/store").Subscriber<Doc<T>>, invalidate?: import("svelte/store").Invalidator<Doc<T>>) => import("svelte/store").Unsubscriber;
7
8
  change: (fn: ChangeFn<T>) => void;
8
9
  };
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAGzD,OAAO,EACL,IAAI,EACJ,UAAU,EAEX,MAAM,2BAA2B,CAAA;AAIlC,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,QAExC;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU;;iBAWjC,SAAS,CAAC,CAAC;EAI3B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EACL,YAAY,EAEZ,IAAI,EACL,MAAM,2BAA2B,CAAA;AAMlC,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,QAExC;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,YAAY;;iBAWnC,SAAS,CAAC,CAAC;EAI3B"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { setContext, getContext } from "svelte";
1
+ import { getContext, setContext } from "svelte";
2
2
  import { writable } from "svelte/store";
3
3
  const ContextRepoKey = Symbol("svelte-context-automerge-repo");
4
4
  export function getContextRepo() {
@@ -10,10 +10,10 @@ export function setContextRepo(repo) {
10
10
  export function document(documentId) {
11
11
  const repo = getContextRepo();
12
12
  const handle = repo.find(documentId);
13
- const { set, subscribe } = writable(null, () => {
14
- const onPatch = (h) => set(h.patchInfo.after);
15
- handle.addListener("patch", onPatch);
16
- return () => handle.removeListener("patch", onPatch);
13
+ const { set, subscribe } = writable(handle.docSync(), () => {
14
+ const onChange = (h) => set(h.doc);
15
+ handle.addListener("change", onChange);
16
+ return () => handle.removeListener("change", onChange);
17
17
  });
18
18
  return {
19
19
  subscribe,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automerge/automerge-repo-svelte-store",
3
- "version": "0.2.1",
3
+ "version": "1.0.0-alpha.0",
4
4
  "description": "A Svelte store containing your automerge documentsj",
5
5
  "repository": "https://github.com/automerge/automerge-repo",
6
6
  "license": "MIT",
@@ -11,9 +11,12 @@
11
11
  "build": "tsc",
12
12
  "watch": "npm-watch"
13
13
  },
14
+ "peerDependencies": {
15
+ "@automerge/automerge": "^2.1.0-alpha.9"
16
+ },
14
17
  "dependencies": {
15
- "@automerge/automerge-repo": "^0.2.1",
16
- "svelte": "^3.0.0"
18
+ "@automerge/automerge-repo": "^1.0.0-alpha.0",
19
+ "svelte": ">=3.0.0"
17
20
  },
18
21
  "watch": {
19
22
  "build": {
@@ -26,5 +29,5 @@
26
29
  "publishConfig": {
27
30
  "access": "public"
28
31
  },
29
- "gitHead": "7f048ecaa62eb1246f54773c6b10bada0767497b"
32
+ "gitHead": "38c0c32796ddca5f86a2e55ab0f1202a2ce107c8"
30
33
  }
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { Doc, ChangeFn } from "@automerge/automerge"
2
- import { setContext, getContext } from "svelte"
3
- import { writable } from "svelte/store"
1
+ import type { ChangeFn, Doc } from "@automerge/automerge"
4
2
  import {
3
+ AutomergeUrl,
4
+ DocHandleChangePayload,
5
5
  Repo,
6
- DocumentId,
7
- DocHandlePatchPayload,
8
6
  } from "@automerge/automerge-repo"
7
+ import { getContext, setContext } from "svelte"
8
+ import { writable } from "svelte/store"
9
9
 
10
10
  const ContextRepoKey = Symbol("svelte-context-automerge-repo")
11
11
 
@@ -17,13 +17,13 @@ export function setContextRepo(repo: Repo) {
17
17
  setContext(ContextRepoKey, repo)
18
18
  }
19
19
 
20
- export function document<T>(documentId: DocumentId) {
20
+ export function document<T>(documentId: AutomergeUrl) {
21
21
  const repo = getContextRepo()
22
22
  const handle = repo.find<T>(documentId)
23
- const { set, subscribe } = writable<Doc<T>>(null, () => {
24
- const onPatch = (h: DocHandlePatchPayload<T>) => set(h.patchInfo.after)
25
- handle.addListener("patch", onPatch)
26
- return () => handle.removeListener("patch", onPatch)
23
+ const { set, subscribe } = writable<Doc<T>>(handle.docSync(), () => {
24
+ const onChange = (h: DocHandleChangePayload<T>) => set(h.doc)
25
+ handle.addListener("change", onChange)
26
+ return () => handle.removeListener("change", onChange)
27
27
  })
28
28
 
29
29
  return {