reptree 0.9.0 → 1.0.1
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/README.md +8 -8
- package/dist/index.cjs +462 -410
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +198 -174
- package/dist/index.d.ts +198 -174
- package/dist/index.js +455 -403
- package/dist/index.js.map +1 -1
- package/package.json +1 -3
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@ RepTree uses [CRDTs](https://crdt.tech/) for seamless replication between users.
|
|
|
8
8
|
|
|
9
9
|
## What it solves
|
|
10
10
|
|
|
11
|
-
If you have a tree structure in your app where each
|
|
11
|
+
If you have a tree structure in your app where each node can be moved independently by multiple users, you need a solution that resolves conflicts when the same node is moved in different ways. Otherwise your tree can diverge or form loops. This includes folder structures (people creating and moving folders), 2D/3D scenes with objects being moved and parented, and Notion‑like documents where blocks with text and other properties are edited by users.
|
|
12
12
|
|
|
13
|
-
You probably also want properties on each
|
|
13
|
+
You probably also want properties on each node and to have them sync correctly between peers without conflicts. RepTree syncs properties too.
|
|
14
14
|
|
|
15
15
|
## Getting started
|
|
16
16
|
|
|
@@ -18,7 +18,7 @@ You probably also want properties on each vertex/node/leaf and to have them sync
|
|
|
18
18
|
npm install reptree
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
### Example 1
|
|
21
|
+
### Example 1
|
|
22
22
|
```ts
|
|
23
23
|
import { RepTree } from "reptree";
|
|
24
24
|
|
|
@@ -26,11 +26,11 @@ import { RepTree } from "reptree";
|
|
|
26
26
|
const tree = new RepTree("company-org-1");
|
|
27
27
|
const company = tree.createRoot();
|
|
28
28
|
|
|
29
|
-
// Create
|
|
29
|
+
// Create nodes in the root of our new tree
|
|
30
30
|
const devs = company.newNamedChild("developers");
|
|
31
31
|
const qa = company.newNamedChild("qa");
|
|
32
32
|
|
|
33
|
-
// Create a
|
|
33
|
+
// Create a node in another node
|
|
34
34
|
const alice = qa.newChild();
|
|
35
35
|
|
|
36
36
|
// Set properties (supports any JSON-serializable values)
|
|
@@ -38,10 +38,10 @@ alice.setProperty("name", "Alice");
|
|
|
38
38
|
alice.setProperty("age", 32);
|
|
39
39
|
alice.setProperty("meta", { department: "QA", skills: ["cypress", "playwright"], flags: { lead: false } });
|
|
40
40
|
|
|
41
|
-
// Move the
|
|
41
|
+
// Move the node inside a different node
|
|
42
42
|
alice.moveTo(devs);
|
|
43
43
|
|
|
44
|
-
// Bind a
|
|
44
|
+
// Bind a node to a type to set its properties like regular fields
|
|
45
45
|
const bob = qa.newChild().bind<{ name: string; age: number }>();
|
|
46
46
|
bob.name = "Bob";
|
|
47
47
|
bob.age = 33;
|
|
@@ -110,7 +110,7 @@ otherTree.merge(ops);
|
|
|
110
110
|
|
|
111
111
|
RepTree uses two conflict-free replicated data types (CRDTs):
|
|
112
112
|
- A move tree CRDT for the tree structure (https://martin.kleppmann.com/papers/move-op.pdf).
|
|
113
|
-
- A last-writer-wins (LWW) CRDT
|
|
113
|
+
- A last-writer-wins (LWW) CRDT for properties.
|
|
114
114
|
|
|
115
115
|
## License
|
|
116
116
|
|