Skip to content

One builder per block event, and queries that take the state (#112, #113) - #124

Merged
shovon merged 2 commits into
mainfrom
worktree-issue-112-113
Oct 28, 2026
Merged

shovon merged 2 commits into
mainfrom
worktree-issue-112-113

Conversation

@shovon

@shovon shovon commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Closes #112. Closes #113.

What changed

Builders (packages/pages/pages.ts): blockEdited(id, text), blockDeleted(id), blockIndented(payload) and blockOutdented(payload) join blockCreated. Each returns { v, type, payload }, with the payload typed against the schema and v from HANDLES, and reads no clock and no randomness.

Commands: editBlock, deleteBlock, indentBlock and outdentBlock (and addBlock) now check against the fold, build and dispatch. append stays as a one-line wrapper that dispatches a built event.

How predict takes them: a builder returns the schema's own variant of PageEvent with v added (blockCreated used to return the whole PageEvent["type"] union, which did not narrow). That is a PageEvent by width, so predict is unchanged and takes a builder's result as it is. PageEvent stays the one shape for "an event this fold reads".

Renderer: the [event, send] pairs move to app/src/renderer/project/PageView/steps/steps.ts, one function per write: add, edit, remove, indent and outdent. Each builds its event with the package's builder and takes only the bridge call it makes (Pick<PagesApi, …>). PageView.tsx no longer writes any `${NAMESPACE}block.*` literal. moving is now a one-line choice between indent and outdent.

Queries (#113): getPage, getPages, getReferences, getPreviews, searchPages and locateBlock take Pages, not PagesView. getPage absorbs pageOf, which was the same function. The PagesView comment loses the line about leaving dispatch throwing. Call sites in pages-store.ts, pages-session.ts, the CLI test and the store test pass view.state.

Docs: app/CLAUDE.md and the package README name the builders and say the queries take the state.

For the reviewer

Tests

  • pages.test.ts:
    • Each command, run on a small outline, writes exactly its builder's event.
    • That event, folded through pagesFold.reduce over the state before, gives the same pages the command left.
    • Each builder's v equals HANDLES[type], and there is one builder for every type in HANDLES.
  • steps.test.ts (new):
    • Each step's event equals the package builder's.
    • Its send makes the matching bridge call with the same arguments.
    • A move with nowhere to go is no step.
  • Existing tests updated to the new query shape (pages.test.ts, blocks.test.ts, pages-store.test.ts, cli.test.ts).
  • npm test at the root (all workspaces pass), plus npm run typecheck and npm run lint in app/, all pass.
  • Not run in the app or Storybook. The change to PageView is covered by the typecheck and the steps test.

🤖 Generated with Claude Code

shovon and others added 2 commits October 27, 2026 17:22
)

Every block event now has a pure builder in @pbnotes/pages: blockCreated,
blockEdited, blockDeleted, blockIndented and blockOutdented. Each returns
{ v, type, payload } with the payload typed against the schema and v from
HANDLES, and reads no clock and no randomness. The commands check against
the fold, build and dispatch; append now only dispatches a built event.

A builder's result is the schema's own variant of PageEvent plus v, so it
is a PageEvent by width and predict takes it as it is. PageEvent stays the
one shape for an event the fold reads.

PageView builds its predictions with the same builders. The [event, send]
pairs move to PageView/steps, one function per write (add, edit, remove,
indent, outdent), each taking only the bridge call it makes. The four
hand-written event literals and the two in moving are gone.

The queries (getPage, getPages, getReferences, getPreviews, searchPages,
locateBlock) take Pages instead of a whole PagesView, since none of them
dispatches. getPage absorbs pageOf, which was the same function. The
PagesView comment no longer tells readers to leave dispatch throwing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shovon
shovon merged commit d7d61c0 into main Oct 28, 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: queries take the fold state, not the whole view pages: one builder per block event, shared by the commands and the renderer

1 participant