Skip to content

pages: fold state in Map, not Record (#146) - #149

Merged
shovon merged 1 commit into
mainfrom
issue-146
Oct 30, 2026
Merged

shovon merged 1 commit into
mainfrom
issue-146

Conversation

@shovon

@shovon shovon commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Closes #146.

Pages.blocks and Pages.titles are now Maps, like Pages.properties already was. A title is whatever was typed, so as a plain-object key toString or __proto__ collided with inherited properties (#62), and every reader needed an Object.hasOwn guard. With Map those guards are gone.

Changes

  • blocks.ts: Pages type, blocksOn, titleOf, spell (copies once, on the first new name; same map back when nothing is new), find, onBlock, reduce's block.created, predict.
  • pages.ts: pagesFold.initial, getPages, getReferences, getPreviews, searchPages.
  • properties.ts: the titles constraint on reduceProperties.
  • Tests: blocks.test.ts, and one app test (pages-session.test.ts) that read state.blocks directly.

Safety

  • The fold state is never serialized to JSON: checkpoints are held in memory (ledger.ts), and only events are written (records.ts).
  • The renderer is sent Pages, never the fold state, so nothing crossing IPC changes shape.

Checks

  • npm test across workspaces: all pass, including the Object.prototype title test without the guards.
  • npm run typecheck: clean.

🤖 Generated with Claude Code

Pages.blocks and Pages.titles were plain objects keyed by a typed title,
so `toString` or `__proto__` hit what every object inherits (#62) and
every reader needed an Object.hasOwn guard. They are Maps now, like
Pages.properties already was, and the guards are gone.

The state only ever crosses a structured clone or stays in memory as a
checkpoint, and a Map survives both; nothing serializes it to JSON.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shovon
shovon merged commit a3f6537 into main Oct 30, 2026
1 check passed
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.

pages: fold state uses Map, not Record, for blocks and titles

1 participant