![import { LoroDoc } from "loro-crdt"; import { schema, SyncDirection, Mirror } from "loro-mirror"; // 1) Declare state shape – a MovableList of todos with stable Container ID `$cid` type TodoStatus = "todo" | "inProgress" | "done"; const appSchema = schema({ todos: schema.LoroMovableList( schema.LoroMap({ text: schema.String(), status: schema.String<TodoStatus>(), }), // $cid is the container ID of LoroMap assigned by Loro (t) => t.$cid, ), }); // 2) Create a Loro document and a Mirror store const doc = new LoroDoc(); const store = new Mirror({ doc, schema: appSchema, // InitialState will not be written into LoroDoc initialState: { todos: [] }, }); // 3) Subscribe (optional) – know whether updates came from local or remote const unsubscribe = store.subscribe((state, { direction, tags }) => { if (direction === SyncDirection.FROM_LORO) { console.log("Remote update", { state, tags }); } else { console.log("Local update", { state, tags](https://pbs.twimg.com/media/G1c2oSSaAAE4jgO.jpg?name=small&format=webp)
ALT import { LoroDoc } from "loro-crdt"; import { schema, SyncDirection, Mirror } from "loro-mirror"; // 1) Declare state shape – a MovableList of todos with stable Container ID `$cid` type TodoStatus = "todo" | "inProgress" | "done"; const appSchema = schema({ todos: schema.LoroMovableList( schema.LoroMap({ text: schema.String(), status: schema.String<TodoStatus>(), }), // $cid is the container ID of LoroMap assigned by Loro (t) => t.$cid, ), }); // 2) Create a Loro document and a Mirror store const doc = new LoroDoc(); const store = new Mirror({ doc, schema: appSchema, // InitialState will not be written into LoroDoc initialState: { todos: [] }, }); // 3) Subscribe (optional) – know whether updates came from local or remote const unsubscribe = store.subscribe((state, { direction, tags }) => { if (direction === SyncDirection.FROM_LORO) { console.log("Remote update", { state, tags }); } else { console.log("Local update", { state, tags

















