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
-`new Mirror(options)`: Creates a bidirectional sync between app state and a `LoroDoc`.
205
+
-**`doc`**: `LoroDoc` – required Loro document instance.
206
+
-**`schema`**: root schema – optional but recommended for strong typing and validation.
207
+
-**`initialState`**: partial state – merged with schema defaults and current doc JSON.
208
+
-**`validateUpdates`**: boolean (default `true`) – validate new state against schema.
209
+
-**`throwOnValidationError`**: boolean (default `false`) – throw on invalid updates.
210
+
-**`debug`**: boolean (default `false`) – log diffs and applied changes.
211
+
-**`inferOptions`**: `{ defaultLoroText?: boolean; defaultMovableList?: boolean }` – influence container-type inference when inserting containers from plain values.
212
+
213
+
-`getState(): State`: Returns the current in-memory state view.
214
+
-`setState(updater, options?)`: Update state and sync to Loro.
215
+
-**`updater`**: either a partial object to shallow-merge or a function that may mutate a draft (Immer-style) or return a new state object.
216
+
-**`options`**: `{ tags?: string | string[] }` – arbitrary tags attached to this update; delivered to subscribers in metadata.
217
+
-`subscribe(callback): () => void`: Subscribe to state changes. `callback` receives `(state, metadata)` where `metadata` includes:
218
+
-**`direction`**: `SyncDirection` – `FROM_LORO` when changes came from the doc, `TO_LORO` when produced locally, `BIDIRECTIONAL` for manual/initial syncs.
219
+
-**`tags`**: `string[] | undefined` – tags provided via `setState`.
220
+
-`dispose()`: Unsubscribe internal listeners and clear subscribers.
221
+
222
+
#### Notes
223
+
224
+
-**Lists and IDs**: If your list schema provides an `idSelector`, list updates use minimal add/remove/update/move operations; otherwise index-based diffs are applied.
225
+
-**Container inference**: When schema is missing/ambiguous for a field, the mirror infers container types from values. `inferOptions.defaultLoroText` makes strings become `LoroText`; `inferOptions.defaultMovableList` makes arrays become `LoroMovableList`.
226
+
227
+
### Types
228
+
229
+
-`SyncDirection`:
230
+
-`FROM_LORO` – applied due to incoming `LoroDoc` changes
0 commit comments