Skip to content

Conversation

@zxch3n
Copy link
Member

@zxch3n zxch3n commented Sep 9, 2025

  • 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 }

  - 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 }
@zxch3n zxch3n changed the title > feat(core): add withCid ($cid) support for maps and tree node.data feat(core): add withCid ($cid) support for maps and tree node.data Sep 9, 2025
@zxch3n zxch3n merged commit b031b09 into main Sep 10, 2025
1 check passed
@zxch3n zxch3n deleted the feat-cid-support branch September 10, 2025 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant