Commit b031b09
authored
feat(core): add withCid ($cid) support for maps and tree node.data (#19)
* > feat(core): add withCid ($cid) support for maps and tree node.data
- Add CID_KEY constant ($cid) to identify container id in mirrored state
- Types: extend InferType so LoroMap/LoroMapRecord with { withCid: true }
infer { ...; $cid: string }; add tree node variant when nodeSchema has withCid
- Mirror snapshot: register roots before snapshot; add containerToStateJson and
buildRootStateSnapshot to normalize trees and inject $cid; use in
initialize + checkStateConsistency
- Events: extend applyEventBatchToState with optional options object
{ getContainerById, containerToJson, nodeDataWithCid, getNodeDataCid }
(backward compatible with function arg); stamp $cid on tree “create” during
event application; container inserts (map/list) go through containerToJson
- Writes: ignore $cid in diffMap and map initialization/updates (read-only)
- Tests: add packages/core/tests/cid.test.ts covering initial snapshot,
event inserts, tree creates, and diff ignoring $cid (use doc.commit where needed)
- Docs: update root README and packages/core/README.md to document withCid,
$cid semantics, and examples (e.g., list idSelector via x => x.$cid)
- Plan: update plan.md with completed progress and changelog
Notes:
- $cid exists only in mirrored state; it is never written to Loro
- No behavior change for maps without { withCid: true }
* fix: ensure cids can be assigned on new containers created by setState
* refactor: simplify types
* fix(core): robust bidirectional sync, cleanup debug, and generalize map updates
* chore: fix lint
* docs: refine docs
* test: confirm got correct types1 parent 2b48f76 commit b031b09
File tree
16 files changed
+1133
-272
lines changed- packages
- core
- src
- core
- schema
- tests
- core
- jotai
- react
16 files changed
+1133
-272
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | 16 | | |
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
25 | 22 | | |
| 23 | + | |
26 | 24 | | |
27 | 25 | | |
28 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
| |||
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
66 | | - | |
67 | 70 | | |
68 | 71 | | |
69 | 72 | | |
| |||
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
76 | | - | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
80 | | - | |
| 82 | + | |
| 83 | + | |
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
| |||
115 | 118 | | |
116 | 119 | | |
117 | 120 | | |
| 121 | + | |
118 | 122 | | |
| 123 | + | |
119 | 124 | | |
120 | 125 | | |
121 | 126 | | |
| |||
130 | 135 | | |
131 | 136 | | |
132 | 137 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
138 | 145 | | |
139 | 146 | | |
140 | 147 | | |
141 | 148 | | |
142 | 149 | | |
143 | | - | |
| 150 | + | |
144 | 151 | | |
145 | 152 | | |
146 | 153 | | |
147 | 154 | | |
148 | 155 | | |
149 | | - | |
| 156 | + | |
150 | 157 | | |
151 | 158 | | |
152 | 159 | | |
| |||
162 | 169 | | |
163 | 170 | | |
164 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
165 | 182 | | |
166 | 183 | | |
167 | 184 | | |
| |||
194 | 211 | | |
195 | 212 | | |
196 | 213 | | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
203 | 222 | | |
204 | 223 | | |
205 | 224 | | |
| |||
208 | 227 | | |
209 | 228 | | |
210 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
211 | 234 | | |
212 | 235 | | |
213 | 236 | | |
| |||
216 | 239 | | |
217 | 240 | | |
218 | 241 | | |
219 | | - | |
| 242 | + | |
220 | 243 | | |
221 | 244 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
227 | 253 | | |
228 | 254 | | |
229 | 255 | | |
| |||
246 | 272 | | |
247 | 273 | | |
248 | 274 | | |
249 | | - | |
250 | | - | |
| 275 | + | |
| 276 | + | |
251 | 277 | | |
252 | 278 | | |
253 | 279 | | |
254 | 280 | | |
255 | 281 | | |
256 | 282 | | |
257 | | - | |
| 283 | + | |
258 | 284 | | |
259 | 285 | | |
260 | 286 | | |
261 | | - | |
| 287 | + | |
262 | 288 | | |
263 | 289 | | |
264 | 290 | | |
| |||
274 | 300 | | |
275 | 301 | | |
276 | 302 | | |
277 | | - | |
278 | 303 | | |
279 | 304 | | |
280 | 305 | | |
| |||
378 | 403 | | |
379 | 404 | | |
380 | 405 | | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
387 | 414 | | |
388 | 415 | | |
389 | 416 | | |
| |||
403 | 430 | | |
404 | 431 | | |
405 | 432 | | |
406 | | - | |
407 | 433 | | |
408 | 434 | | |
409 | 435 | | |
410 | 436 | | |
411 | 437 | | |
412 | 438 | | |
413 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
414 | 446 | | |
415 | 447 | | |
416 | 448 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
40 | | - | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
46 | | - | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
121 | | - | |
| 123 | + | |
122 | 124 | | |
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
128 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
129 | 135 | | |
130 | 136 | | |
131 | 137 | | |
| |||
159 | 165 | | |
160 | 166 | | |
161 | 167 | | |
162 | | - | |
163 | | - | |
| 168 | + | |
| 169 | + | |
164 | 170 | | |
165 | 171 | | |
166 | 172 | | |
| |||
174 | 180 | | |
175 | 181 | | |
176 | 182 | | |
177 | | - | |
| 183 | + | |
178 | 184 | | |
179 | 185 | | |
180 | 186 | | |
181 | 187 | | |
182 | 188 | | |
183 | 189 | | |
184 | 190 | | |
185 | | - | |
| 191 | + | |
186 | 192 | | |
187 | 193 | | |
188 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
963 | 964 | | |
964 | 965 | | |
965 | 966 | | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
966 | 975 | | |
967 | 976 | | |
968 | 977 | | |
| |||
982 | 991 | | |
983 | 992 | | |
984 | 993 | | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
985 | 1002 | | |
986 | 1003 | | |
987 | 1004 | | |
| |||
0 commit comments