Skip to content

Commit 0442154

Browse files
authored
fix event apply for new containers (#17)
* docs: update readme * fix: avoid apply event twice for new containers * fix: tree event handle
1 parent 3990702 commit 0442154

File tree

9 files changed

+366
-598
lines changed

9 files changed

+366
-598
lines changed

README.md

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pnpm add loro-mirror loro-crdt
3131

3232
## Quick Start
3333

34-
### Core Usage
34+
### Usage
3535

3636
```typescript
3737
import { LoroDoc } from "loro-crdt";
@@ -99,27 +99,27 @@ Loro Mirror provides a declarative schema system that enables:
9999
- **Root Schema**: The root object defined via `schema({...})`, containing only Loro container types (Map/List/Text/MovableList).
100100
- **Field Schema**: A combination of primitive types (string, number, boolean), ignore fields, and Loro containers.
101101
- **Schema Options (`SchemaOptions`)**:
102-
- **`required?: boolean`**: Whether the field is required (default: `true`).
103-
- **`defaultValue?: unknown`**: Default value for the field.
104-
- **`description?: string`**: Description of the field.
105-
- **`validate?: (value) => boolean | string`**: Custom validation function. Return `true` for valid values, or a string as error message for invalid ones.
102+
- **`required?: boolean`**: Whether the field is required (default: `true`).
103+
- **`defaultValue?: unknown`**: Default value for the field.
104+
- **`description?: string`**: Description of the field.
105+
- **`validate?: (value) => boolean | string`**: Custom validation function. Return `true` for valid values, or a string as error message for invalid ones.
106106

107107
#### Schema Definition API
108108

109109
- **Primitive Types**:
110-
- `schema.String<T extends string = string>(options?)` - String type with optional generic constraint
111-
- `schema.Number(options?)` - Number type
112-
- `schema.Boolean(options?)` - Boolean type
113-
- `schema.Ignore(options?)` - Field that won't sync with Loro, useful for local computed fields
110+
- `schema.String<T extends string = string>(options?)` - String type with optional generic constraint
111+
- `schema.Number(options?)` - Number type
112+
- `schema.Boolean(options?)` - Boolean type
113+
- `schema.Ignore(options?)` - Field that won't sync with Loro, useful for local computed fields
114114

115115
- **Container Types**:
116-
- `schema.LoroMap(definition, options?)` - Object container that can nest arbitrary field schemas
117-
- Supports dynamic key-value definition with `catchall`: `schema.LoroMap({...}).catchall(valueSchema)`
118-
- `schema.LoroMapRecord(valueSchema, options?)` - Equivalent to `LoroMap({}).catchall(valueSchema)` for homogeneous maps
119-
- `schema.LoroList(itemSchema, idSelector?, options?)` - Ordered list container
120-
- Providing an `idSelector` (e.g., `(item) => item.id`) enables minimal add/remove/update/move diffs
121-
- `schema.LoroMovableList(itemSchema, idSelector, options?)` - List with native move operations, requires an `idSelector`
122-
- `schema.LoroText(options?)` - Collaborative text editing container
116+
- `schema.LoroMap(definition, options?)` - Object container that can nest arbitrary field schemas
117+
- Supports dynamic key-value definition with `catchall`: `schema.LoroMap({...}).catchall(valueSchema)`
118+
- `schema.LoroMapRecord(valueSchema, options?)` - Equivalent to `LoroMap({}).catchall(valueSchema)` for homogeneous maps
119+
- `schema.LoroList(itemSchema, idSelector?, options?)` - Ordered list container
120+
- Providing an `idSelector` (e.g., `(item) => item.id`) enables minimal add/remove/update/move diffs
121+
- `schema.LoroMovableList(itemSchema, idSelector, options?)` - List with native move operations, requires an `idSelector`
122+
- `schema.LoroText(options?)` - Collaborative text editing container
123123

124124
#### Type Inference
125125

@@ -128,7 +128,7 @@ Automatically derive strongly-typed state from your schema:
128128
```ts
129129
import { schema } from "loro-mirror";
130130

131-
type UserId = string & { __brand: "userId" }
131+
type UserId = string & { __brand: "userId" };
132132
const appSchema = schema({
133133
user: schema.LoroMap({
134134
id: schema.String<UserId>(),
@@ -151,7 +151,9 @@ type AppState = InferType<typeof appSchema>;
151151
For `LoroMap` with dynamic key-value pairs:
152152

153153
```ts
154-
const mapWithCatchall = schema.LoroMap({ fixed: schema.Number() }).catchall(schema.String());
154+
const mapWithCatchall = schema
155+
.LoroMap({ fixed: schema.Number() })
156+
.catchall(schema.String());
155157
// Type: { fixed: number } & { [k: string]: string }
156158

157159
const record = schema.LoroMapRecord(schema.Boolean());
@@ -164,11 +166,11 @@ When a field has `required: false`, the corresponding type becomes optional (uni
164166

165167
- Explicitly specified `defaultValue` takes the highest precedence.
166168
- Built-in defaults for fields without `defaultValue` and `required: true`:
167-
- **String / LoroText**`""`
168-
- **Number**`0`
169-
- **Boolean**`false`
170-
- **LoroList**`[]`
171-
- **LoroMap / Root** → Recursively aggregated defaults from child fields
169+
- **String / LoroText**`""`
170+
- **Number**`0`
171+
- **Boolean**`false`
172+
- **LoroList**`[]`
173+
- **LoroMap / Root** → Recursively aggregated defaults from child fields
172174

173175
#### Runtime Validation
174176

@@ -305,7 +307,7 @@ function AddTodoForm() {
305307

306308
For detailed documentation, see the README files in each package:
307309

308-
- [Core Documentation](./packages/core/README.md)
310+
- [Loro Mirror Documentation](./packages/core/README.md)
309311
- [React Documentation](./packages/react/README.md)
310312
- [Jotai Documentation](./packages/jotai/README.md)
311313

0 commit comments

Comments
 (0)