Skip to content

Commit

Permalink
chore: release
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Apr 26, 2024
1 parent 31a8569 commit 35b9b6e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .changeset/tidy-cameras-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
"loro-wasm": minor
"loro-crdt": minor
---

Movable List (#293)

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.

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.

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.

## Example

```ts
import { Loro } from "loro-crdt";
import { expect } from "vitest";

const doc = new Loro();
const list = doc.getMovableList("list");
list.push("a");
list.push("b");
list.push("c");
expect(list.toArray()).toEqual(["a", "b", "c"]);
list.set(2, "d");
list.move(0, 1);
const doc2 = new Loro();
const list2 = doc2.getMovableList("list");
expect(list2.length).toBe(0);
doc2.import(doc.exportFrom());
expect(list2.length).toBe(3);
expect(list2.get(0)).toBe("b");
expect(list2.get(1)).toBe("a");
expect(list2.get(2)).toBe("d");
```

0 comments on commit 35b9b6e

Please sign in to comment.