Skip to content

Commit 1697ef9

Browse files
committed
add naïve support for conflicts and increments
1 parent 5fd232a commit 1697ef9

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
"dependencies": {
5151
"@solid-primitives/utils": "^6.3.0",
52-
"cabbages": "^0.1.0"
52+
"cabbages": "^0.2.2"
5353
},
5454
"repository": {
5555
"type": "git",

pnpm-lock.yaml

Lines changed: 22 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/autoproduce.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {Patch} from "@automerge/automerge-repo/slim"
1+
import type {DocHandleChangePayload} from "@automerge/automerge-repo/slim"
22
import {apply, fromAutomerge} from "cabbages"
33

44
/**
@@ -10,11 +10,10 @@ import {apply, fromAutomerge} from "cabbages"
1010
* [Solid
1111
* Stores](https://docs.solidjs.com/reference/store-utilities/create-store)
1212
*/
13-
export default function autoproduce<T>(patches: Patch[]) {
13+
export default function autoproduce<T>(payload: DocHandleChangePayload<T>) {
1414
return (doc: T) => {
15-
for (let patch of patches) {
16-
const [path, range, val] = fromAutomerge(patch)
17-
apply(path, doc, range, val)
15+
for (let patch of payload.patches) {
16+
apply(doc, ...fromAutomerge(patch, payload))
1817
}
1918
}
2019
}

src/makeDocumentProjection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default function makeDocumentProjection<T>(handle: DocHandle<T>) {
4444
})
4545

4646
function patch(payload: DocHandleChangePayload<T>) {
47-
set(produce(autoproduce(payload.patches)))
47+
set(produce(autoproduce(payload)))
4848
}
4949

5050
function ondelete() {

test/makeDocumentProjection.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,25 @@ describe("makeDocumentProjection", () => {
141141
})
142142
})
143143

144+
it.only("should be handle conflict well", async () => {
145+
const {repo} = setup()
146+
const handle1 = repo.create({a: true})
147+
const promise = new Promise<void>(resolve => {
148+
handle1.on("change", payload => {
149+
console.log(payload.patches.map(p => p.action))
150+
expect(payload.patches[0].action).toBe("conflict")
151+
resolve()
152+
})
153+
const handle2 = repo.create({
154+
a: {b: {c: {d: {e: {f: [1, 2, 3, {g: 4}]}}}}},
155+
})
156+
handle1.merge(handle2)
157+
})
158+
159+
// expect(handle1.doc().a).toEqual(true)
160+
return promise
161+
})
162+
144163
it("should not clean up when it should not clean up", async () => {
145164
const {handle} = setup()
146165

0 commit comments

Comments
 (0)