Skip to content

Commit 35b9b6e

Browse files
committed
chore: release
1 parent 31a8569 commit 35b9b6e

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

.changeset/tidy-cameras-scream.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
"loro-wasm": minor
3+
"loro-crdt": minor
4+
---
5+
6+
Movable List (#293)
7+
8+
Loro's List supports insert and delete operations but lacks built-in methods for `set` and `move`. To simulate set and move, developers might combine delete and insert. However, this approach can lead to issues during concurrent operations on the same element, often resulting in duplicate entries upon merging.
9+
10+
For instance, consider a list [0, 1, 2]. If user A moves the element '0' to position 1, while user B moves it to position 2, the ideal merged outcome should be either [1, 0, 2] or [1, 2, 0]. However, using the delete-insert method to simulate a move results in [1, 0, 2, 0], as both users delete '0' from its original position and insert it independently at new positions.
11+
12+
To address this, we introduce a MovableList container. This new container type directly supports move and set operations, aligning more closely with user expectations and preventing the issues associated with simulated moves.
13+
14+
## Example
15+
16+
```ts
17+
import { Loro } from "loro-crdt";
18+
import { expect } from "vitest";
19+
20+
const doc = new Loro();
21+
const list = doc.getMovableList("list");
22+
list.push("a");
23+
list.push("b");
24+
list.push("c");
25+
expect(list.toArray()).toEqual(["a", "b", "c"]);
26+
list.set(2, "d");
27+
list.move(0, 1);
28+
const doc2 = new Loro();
29+
const list2 = doc2.getMovableList("list");
30+
expect(list2.length).toBe(0);
31+
doc2.import(doc.exportFrom());
32+
expect(list2.length).toBe(3);
33+
expect(list2.get(0)).toBe("b");
34+
expect(list2.get(1)).toBe("a");
35+
expect(list2.get(2)).toBe("d");
36+
```

0 commit comments

Comments
 (0)