@automerge/automerge-repo-svelte-store 2.0.0-alpha.20 → 2.0.0-alpha.22
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/package.json +5 -5
- package/src/index.ts +1 -1
- package/dist/index.d.ts +0 -74
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -89
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automerge/automerge-repo-svelte-store",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
4
|
-
"description": "A Svelte store containing your automerge
|
|
3
|
+
"version": "2.0.0-alpha.22",
|
|
4
|
+
"description": "A Svelte store containing your automerge documents",
|
|
5
5
|
"repository": "https://github.com/automerge/automerge-repo/tree/master/packages/automerge-repo-svelte-store",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "
|
|
10
|
+
"build": "",
|
|
11
11
|
"watch": "npm-watch build"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"svelte": "^3.0.0 || ^4.0.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@automerge/automerge-repo": "2.0.0-alpha.
|
|
18
|
+
"@automerge/automerge-repo": "2.0.0-alpha.22"
|
|
19
19
|
},
|
|
20
20
|
"watch": {
|
|
21
21
|
"build": {
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "b30af9827bed4615ba3c5e9ee93ca483915e4016"
|
|
32
32
|
}
|
package/src/index.ts
CHANGED
|
@@ -87,7 +87,7 @@ export function setContextRepo(repo: Repo) {
|
|
|
87
87
|
export function document<T>(documentId: AutomergeUrl, repo?: Repo) {
|
|
88
88
|
repo = repo ?? getContextRepo()
|
|
89
89
|
const handle = repo.find<T>(documentId)
|
|
90
|
-
const { set, subscribe } = writable<Doc<T>>(handle.
|
|
90
|
+
const { set, subscribe } = writable<Doc<T>>(handle.doc(), () => {
|
|
91
91
|
const onChange = (h: DocHandleChangePayload<T>) => set(h.doc)
|
|
92
92
|
handle.addListener("change", onChange)
|
|
93
93
|
return () => handle.removeListener("change", onChange)
|
package/dist/index.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* # Svelte store for Automerge Repo
|
|
3
|
-
*
|
|
4
|
-
* ## Example Usage
|
|
5
|
-
*
|
|
6
|
-
* For a working example, see the [Svelte counter demo](../automerge-repo-demo-counter-svelte/).
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```svelte
|
|
11
|
-
* // App.svelte
|
|
12
|
-
* <script lang="ts">
|
|
13
|
-
* import { Repo } from "@automerge/automerge-repo"
|
|
14
|
-
* import Counter from './lib/Counter.svelte'
|
|
15
|
-
* import { setContextRepo } from "@automerge/automerge-repo-svelte-store"
|
|
16
|
-
*
|
|
17
|
-
* const repo = new Repo({storage: new SomeStorage() })
|
|
18
|
-
*
|
|
19
|
-
* // Make the `Repo` available to child components (via Svelte's `setContext`).
|
|
20
|
-
* setContextRepo(repo)
|
|
21
|
-
*
|
|
22
|
-
* const docId = repo.create()
|
|
23
|
-
* </script>
|
|
24
|
-
*
|
|
25
|
-
* <main>
|
|
26
|
-
* <div class="card">
|
|
27
|
-
* <Counter {docId}/>
|
|
28
|
-
* </div>
|
|
29
|
-
* </main>
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* ```svelte
|
|
34
|
-
* // Counter.svelte`
|
|
35
|
-
* <script lang="ts">
|
|
36
|
-
* import type { DocumentId } from "@automerge/automerge-repo"
|
|
37
|
-
* import { document } from "@automerge/automerge-repo-svelte-store"
|
|
38
|
-
*
|
|
39
|
-
* export let docId: DocumentId
|
|
40
|
-
*
|
|
41
|
-
* // `document` calls `getContextRepo` internally to access the closest `Repo`.
|
|
42
|
-
* // alternatively, you may pass in a specific repo as the second parameter
|
|
43
|
-
* const doc = document<{count?: number}>(docId)
|
|
44
|
-
* const increment = () => {
|
|
45
|
-
* doc.change((d) => d.count = (d.count || 0) + 1)
|
|
46
|
-
* }
|
|
47
|
-
* </script>
|
|
48
|
-
*
|
|
49
|
-
* <button on:click={increment}>
|
|
50
|
-
* count is {$doc?.count || 0}
|
|
51
|
-
* </button>
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* ## Contributors
|
|
55
|
-
* Originally written by Dylan MacKenzie ([@ecstatic-morse](https://github.com/ecstatic-morse)).
|
|
56
|
-
* * @packageDocumentation
|
|
57
|
-
**/
|
|
58
|
-
import type { ChangeFn, Doc } from "@automerge/automerge/slim/next";
|
|
59
|
-
import { AutomergeUrl, Repo } from "@automerge/automerge-repo/slim";
|
|
60
|
-
export declare function getContextRepo(): Repo;
|
|
61
|
-
export declare function setContextRepo(repo: Repo): void;
|
|
62
|
-
/**
|
|
63
|
-
* A Svelte store for an Automerge document.
|
|
64
|
-
*
|
|
65
|
-
* @param {AutomergeUrl} documentId - The Automerge document ID
|
|
66
|
-
* @param {Repo=} repo - (Optional) The Automerge repo to use. If not provided, the repo will be retrieved from context.
|
|
67
|
-
*
|
|
68
|
-
* @returns A Svelte store for the Automerge document.
|
|
69
|
-
*/
|
|
70
|
-
export declare function document<T>(documentId: AutomergeUrl, repo?: Repo): {
|
|
71
|
-
subscribe: (this: void, run: import("svelte/store").Subscriber<Doc<T>>, invalidate?: import("svelte/store").Invalidator<Doc<T>> | undefined) => import("svelte/store").Unsubscriber;
|
|
72
|
-
change: (fn: ChangeFn<T>) => void;
|
|
73
|
-
};
|
|
74
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAwDI;AAEJ,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EACL,YAAY,EAEZ,IAAI,EACL,MAAM,gCAAgC,CAAA;AAMvC,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,QAExC;AAED;;;;;;;GAOG;AAEH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,IAAI;;iBAWhD,QAAQ,CAAC,CAAC,CAAC;EAI3B"}
|
package/dist/index.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* # Svelte store for Automerge Repo
|
|
3
|
-
*
|
|
4
|
-
* ## Example Usage
|
|
5
|
-
*
|
|
6
|
-
* For a working example, see the [Svelte counter demo](../automerge-repo-demo-counter-svelte/).
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```svelte
|
|
11
|
-
* // App.svelte
|
|
12
|
-
* <script lang="ts">
|
|
13
|
-
* import { Repo } from "@automerge/automerge-repo"
|
|
14
|
-
* import Counter from './lib/Counter.svelte'
|
|
15
|
-
* import { setContextRepo } from "@automerge/automerge-repo-svelte-store"
|
|
16
|
-
*
|
|
17
|
-
* const repo = new Repo({storage: new SomeStorage() })
|
|
18
|
-
*
|
|
19
|
-
* // Make the `Repo` available to child components (via Svelte's `setContext`).
|
|
20
|
-
* setContextRepo(repo)
|
|
21
|
-
*
|
|
22
|
-
* const docId = repo.create()
|
|
23
|
-
* </script>
|
|
24
|
-
*
|
|
25
|
-
* <main>
|
|
26
|
-
* <div class="card">
|
|
27
|
-
* <Counter {docId}/>
|
|
28
|
-
* </div>
|
|
29
|
-
* </main>
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* ```svelte
|
|
34
|
-
* // Counter.svelte`
|
|
35
|
-
* <script lang="ts">
|
|
36
|
-
* import type { DocumentId } from "@automerge/automerge-repo"
|
|
37
|
-
* import { document } from "@automerge/automerge-repo-svelte-store"
|
|
38
|
-
*
|
|
39
|
-
* export let docId: DocumentId
|
|
40
|
-
*
|
|
41
|
-
* // `document` calls `getContextRepo` internally to access the closest `Repo`.
|
|
42
|
-
* // alternatively, you may pass in a specific repo as the second parameter
|
|
43
|
-
* const doc = document<{count?: number}>(docId)
|
|
44
|
-
* const increment = () => {
|
|
45
|
-
* doc.change((d) => d.count = (d.count || 0) + 1)
|
|
46
|
-
* }
|
|
47
|
-
* </script>
|
|
48
|
-
*
|
|
49
|
-
* <button on:click={increment}>
|
|
50
|
-
* count is {$doc?.count || 0}
|
|
51
|
-
* </button>
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* ## Contributors
|
|
55
|
-
* Originally written by Dylan MacKenzie ([@ecstatic-morse](https://github.com/ecstatic-morse)).
|
|
56
|
-
* * @packageDocumentation
|
|
57
|
-
**/
|
|
58
|
-
import { getContext, setContext } from "svelte";
|
|
59
|
-
import { writable } from "svelte/store";
|
|
60
|
-
const ContextRepoKey = Symbol("svelte-context-automerge-repo");
|
|
61
|
-
export function getContextRepo() {
|
|
62
|
-
return getContext(ContextRepoKey);
|
|
63
|
-
}
|
|
64
|
-
export function setContextRepo(repo) {
|
|
65
|
-
setContext(ContextRepoKey, repo);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* A Svelte store for an Automerge document.
|
|
69
|
-
*
|
|
70
|
-
* @param {AutomergeUrl} documentId - The Automerge document ID
|
|
71
|
-
* @param {Repo=} repo - (Optional) The Automerge repo to use. If not provided, the repo will be retrieved from context.
|
|
72
|
-
*
|
|
73
|
-
* @returns A Svelte store for the Automerge document.
|
|
74
|
-
*/
|
|
75
|
-
export function document(documentId, repo) {
|
|
76
|
-
repo = repo ?? getContextRepo();
|
|
77
|
-
const handle = repo.find(documentId);
|
|
78
|
-
const { set, subscribe } = writable(handle.docSync(), () => {
|
|
79
|
-
const onChange = (h) => set(h.doc);
|
|
80
|
-
handle.addListener("change", onChange);
|
|
81
|
-
return () => handle.removeListener("change", onChange);
|
|
82
|
-
});
|
|
83
|
-
return {
|
|
84
|
-
subscribe,
|
|
85
|
-
change: (fn) => {
|
|
86
|
-
handle.change(fn);
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
}
|