Skip to content

Commit 96852e1

Browse files
committed
chore: fix code examples and make tests pass
1 parent 8401513 commit 96852e1

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

deno.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deno_scripts/loro.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LoroDoc } from "npm:loro-crdt@1.0.0-beta.5";
1+
import { LoroDoc } from "npm:loro-crdt@1.5.2";
22

33
const doc = new LoroDoc();
44
doc.getCursorPos;

deno_scripts/run_code_blocks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { walk } from "jsr:@std/fs";
22
import { CodeBlock, extractCodeBlocks } from "./extract_code_blocks.ts";
33
import { resolve } from "https://deno.land/[email protected]/path/mod.ts";
44

5-
const LORO_VERSION = "1.2.5";
5+
const LORO_VERSION = "1.5.2";
66

77
async function* scanMarkdownFiles(dir: string): AsyncGenerator<CodeBlock[]> {
88
// Walking through the directory to find markdown files
@@ -71,7 +71,7 @@ for await (const blocks of scanMarkdownFiles(targetDir)) {
7171
}
7272
await Deno.stdout.write(
7373
new TextEncoder().encode(
74-
`\r🧪 ${testCases} tests, ✅ ${passed} passed, ❌ ${failed} failed`,
74+
`\r🧪 ${testCases} tests, ✅ ${passed} passed, ❌ ${failed} failed`,
7575
),
7676
);
7777
}));

pages/changelog/v1.5.0.mdx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ expect(doc.getChangeAt({ peer: "0", counter: 0 }).message).toBe("test");
2525

2626
Advanced Example - Creating a Merkle DAG:
2727

28-
```ts
28+
```ts no_run
2929
const doc = new LoroDoc();
3030
doc.setPeerId(0);
3131
doc.subscribePreCommit((e) => {
@@ -73,7 +73,7 @@ EphemeralStore is a better alternative to Awareness for ephemeral states:
7373

7474
Awareness is commonly used as a state-based CRDT for handling ephemeral states in real-time collaboration scenarios, such as cursor positions and application component highlights. As application complexity grows, Awareness may be set in multiple places, from cursor positions to user presence. However, the current version of Awareness doesn't support partial state updates, which means even minor mouse movements require synchronizing the entire Awareness state.
7575

76-
```ts
76+
```ts no_run
7777
awareness.setLocalState({
7878
...awareness.getLocalState(),
7979
x: 167,
@@ -91,20 +91,26 @@ import {
9191

9292
const store = new EphemeralStore();
9393
// Set ephemeral data
94-
store.set("loro-prosemirror", {
95-
anchor: ...,
96-
focus: ...,
94+
store.set("user-alice", {
95+
anchor: 10,
96+
focus: 20,
9797
user: "Alice"
9898
});
99-
store.set("online-users", ["Alice", "Bob"]);
10099

101-
expect(storeB.get("online-users")).toEqual(["Alice", "Bob"]);
102100
// Encode only the data for `loro-prosemirror`
103-
const encoded = store.encode("loro-prosemirror")
104-
105-
store.subscribe((e: EphemeralStoreEvent) => {
101+
const encoded = store.encode("user-alice")
102+
const newStore = new EphemeralStore();
103+
newStore.subscribe((e: EphemeralStoreEvent) => {
106104
// Listen to changes from `local`, `remote`, or `timeout` events
107105
});
106+
107+
newStore.apply(encoded);
108+
console.log(newStore.get("user-alice"))
109+
// {
110+
// anchor: 10,
111+
// focus: 20,
112+
// user: "Alice"
113+
// }
108114
```
109115

110116
## Fix

pages/docs/advanced/undo.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ The `onPush` and `onPop` callbacks are triggered when these stacks change:
204204

205205
The `mergeInterval` option in the UndoManager controls how closely spaced operations are grouped:
206206

207-
```ts
207+
```ts no_run
208208
const undoManager = new UndoManager(doc, {
209209
mergeInterval: 1000, // 1000ms = 1 second (default)
210210
});

0 commit comments

Comments
 (0)