-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add a method to find id spans between frontiers * feat(wasm): expose frontiers (from&to) in event * test: fix test * chore: changeset * refactor: rename to findIdSpansBetween * test: fix test err * refactor: rename the fields of version vector diff replace `left` and `right` with `retreat` and `forward` * docs: add more details about find_id_spans_between
- Loading branch information
Showing
14 changed files
with
440 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"loro-crdt": minor | ||
--- | ||
|
||
feat: find id spans between #607 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,60 @@ | ||
import init, { initSync, LoroDoc, LoroMap } from "../web/loro_wasm.js"; | ||
import init, { initSync, LoroDoc, LoroMap, LoroText } from "../web/index.js"; | ||
import { expect } from "npm:expect"; | ||
|
||
await init(); | ||
|
||
Deno.test("basic", () => { | ||
const doc = new LoroDoc(); | ||
doc.getText("text").insert(0, "Hello, world!"); | ||
expect(doc.getText("text").toString()).toBe("Hello, world!"); | ||
const doc = new LoroDoc(); | ||
doc.getText("text").insert(0, "Hello, world!"); | ||
expect(doc.getText("text").toString()).toBe("Hello, world!"); | ||
}); | ||
|
||
Deno.test("fork when detached", () => { | ||
const doc = new LoroDoc(); | ||
doc.setPeerId("0"); | ||
doc.getText("text").insert(0, "Hello, world!"); | ||
doc.checkout([{ peer: "0", counter: 5 }]); | ||
const newDoc = doc.fork(); | ||
newDoc.setPeerId("1"); | ||
newDoc.getText("text").insert(6, " Alice!"); | ||
// ┌───────────────┐ ┌───────────────┐ | ||
// │ Hello, │◀─┬──│ world! │ | ||
// └───────────────┘ │ └───────────────┘ | ||
// │ | ||
// │ ┌───────────────┐ | ||
// └──│ Alice! │ | ||
// └───────────────┘ | ||
doc.import(newDoc.export({ mode: "update" })); | ||
doc.checkoutToLatest(); | ||
console.log(doc.getText("text").toString()); // "Hello, world! Alice!" | ||
const doc: LoroDoc = new LoroDoc(); | ||
doc.setPeerId("0"); | ||
doc.getText("text").insert(0, "Hello, world!"); | ||
doc.checkout([{ peer: "0", counter: 5 }]); | ||
const newDoc = doc.fork(); | ||
newDoc.setPeerId("1"); | ||
newDoc.getText("text").insert(6, " Alice!"); | ||
// ┌───────────────┐ ┌───────────────┐ | ||
// │ Hello, │◀─┬──│ world! │ | ||
// └───────────────┘ │ └───────────────┘ | ||
// │ | ||
// │ ┌───────────────┐ | ||
// └──│ Alice! │ | ||
// └───────────────┘ | ||
doc.import(newDoc.export({ mode: "update" })); | ||
doc.checkoutToLatest(); | ||
console.log(doc.getText("text").toString()); // "Hello, world! Alice!" | ||
}); | ||
|
||
Deno.test("isDeleted", () => { | ||
const doc = new LoroDoc(); | ||
const list = doc.getList("list"); | ||
expect(list.isDeleted()).toBe(false); | ||
const tree = doc.getTree("root"); | ||
const node = tree.createNode(undefined, undefined); | ||
const containerBefore = node.data.setContainer("container", new LoroMap()); | ||
containerBefore.set("A", "B"); | ||
tree.delete(node.id); | ||
const containerAfter = doc.getContainerById(containerBefore.id) as LoroMap; | ||
expect(containerAfter.isDeleted()).toBe(true); | ||
const doc = new LoroDoc(); | ||
const list = doc.getList("list"); | ||
expect(list.isDeleted()).toBe(false); | ||
const tree = doc.getTree("root"); | ||
const node = tree.createNode(undefined, undefined); | ||
const containerBefore = node.data.setContainer("container", new LoroMap()); | ||
containerBefore.set("A", "B"); | ||
tree.delete(node.id); | ||
const containerAfter = doc.getContainerById(containerBefore.id) as LoroMap; | ||
expect(containerAfter.isDeleted()).toBe(true); | ||
}); | ||
|
||
Deno.test("toJsonWithReplacer", () => { | ||
const doc = new LoroDoc(); | ||
const text = doc.getText("text"); | ||
text.insert(0, "Hello"); | ||
text.mark({ start: 0, end: 2 }, "bold", true); | ||
|
||
// Use delta to represent text | ||
// @ts-ignore: deno is not very clever | ||
const json = doc.toJsonWithReplacer((key, value) => { | ||
if (value instanceof LoroText) { | ||
return value.toDelta(); | ||
} | ||
|
||
return value; | ||
}); | ||
}); |
Oops, something went wrong.