You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Lists: always provide an `idSelector` if items have stable IDs — enables minimal add/update/move/delete instead of positional churn. Prefer `LoroMovableList` when reorder operations are common.
221
221
-`$cid` for IDs: Every `LoroMap` includes a stable `$cid` you can use as a React `key` or as a `LoroList` item selector: `(item) => item.$cid`.
222
-
-`setState` styles: choose your favorite — draft mutation or returning a new object. Both are supported and return a Promise. Await in non-React code when you need ordering or to catch validation errors.
222
+
-`setState` styles: choose your favorite — draft mutation or returning a new object. Both run synchronously, so follow-up logic can safely read the updated state immediately.
223
223
- Tagging updates: pass `{ tags: ["analytics", "user"] }` to `setState` and inspect `metadata.tags` in subscribers.
224
224
- Trees: you can create/move/delete nodes in state (Mirror emits precise `tree-create/move/delete`). Node `data` is a normal Loro map — nested containers (text, list, map) update incrementally.
225
225
- Initial state: providing `initialState` hints shapes and defaults in memory, but does not write into the LoroDoc until a real change occurs.
Copy file name to clipboardExpand all lines: packages/core/README.md
+5-6Lines changed: 5 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,17 +32,16 @@ const store = new Mirror({ doc, schema: appSchema });
32
32
// Read state
33
33
const state =store.getState();
34
34
35
-
// Update (return a new state)
36
-
// setState is async; await it in non-React code
37
-
awaitstore.setState({
35
+
// Update (return a new state) — synchronous; the next line sees the new state.
36
+
store.setState({
38
37
...state,
39
38
settings: { ...state.settings, darkMode: true },
40
39
todos: [...state.todos, { text: "Add milk" }],
41
40
notes: "Hello, team!",
42
41
});
43
42
44
43
// Or mutate a draft (Immer-style)
45
-
awaitstore.setState((s) => {
44
+
store.setState((s) => {
46
45
s.todos.push({ text: "Ship" });
47
46
s.settings.title="Project";
48
47
});
@@ -82,7 +81,7 @@ Trees are advanced usage; see Advanced: Trees at the end.
82
81
- inferOptions: `{ defaultLoroText?: boolean; defaultMovableList?: boolean }` for container inference when schema is missing
83
82
- Methods:
84
83
- getState(): Current state
85
-
- setState(updater | partial, options?): Mutate a draft or return a new object. Returns a Promise and should be `await`ed in non-React code when you need the update applied before the next line.
84
+
- setState(updater | partial, options?): Mutate a draft or return a new object. Runs synchronously so downstream logic can immediately read the latest state.
0 commit comments