Repository navigation
One builder per block event, and queries that take the state (#112, #113) - #124
Merged
Merged
Conversation
) 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>
# Conflicts: # app/CLAUDE.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #112. Closes #113.
What changed
Builders (
packages/pages/pages.ts):blockEdited(id, text),blockDeleted(id),blockIndented(payload)andblockOutdented(payload)joinblockCreated. Each returns{ v, type, payload }, with the payload typed against the schema andvfromHANDLES, and reads no clock and no randomness.Commands:
editBlock,deleteBlock,indentBlockandoutdentBlock(andaddBlock) now check against the fold, build and dispatch.appendstays as a one-line wrapper that dispatches a built event.How
predicttakes them: a builder returns the schema's own variant ofPageEventwithvadded (blockCreatedused to return the wholePageEvent["type"]union, which did not narrow). That is aPageEventby width, sopredictis unchanged and takes a builder's result as it is.PageEventstays the one shape for "an event this fold reads".Renderer: the
[event, send]pairs move toapp/src/renderer/project/PageView/steps/steps.ts, one function per write:add,edit,remove,indentandoutdent. Each builds its event with the package's builder and takes only the bridge call it makes (Pick<PagesApi, …>).PageView.tsxno longer writes any`${NAMESPACE}block.*`literal.movingis now a one-line choice betweenindentandoutdent.Queries (#113):
getPage,getPages,getReferences,getPreviews,searchPagesandlocateBlocktakePages, notPagesView.getPageabsorbspageOf, which was the same function. ThePagesViewcomment loses the line about leavingdispatchthrowing. Call sites inpages-store.ts,pages-session.ts, the CLI test and the store test passview.state.Docs:
app/CLAUDE.mdand the package README name the builders and say the queries take the state.For the reviewer
Pages, not{ state }: the bare state made every call site the same or simpler.pages-session.tsreads(await open.require()).state, and the CLI test andblocks.test.tslose a stubdispatch.vfield, whichpredictandreducedon't read.stepsis only about pairing an event with its call, so Pull block placement and caret rules out of PageView and ProjectView #116 can build on it.indentandoutdentresolve the move withindented/outdented, since the event can't be built without that.getStateinpages-store.tsstill takes the app'sPagesViewand reads only.statefrom it. It's the app's function, not one of the package queries, so it's outside pages: queries take the fold state, not the whole view #113. It could be narrowed the same way later.pages-session.tsand there's nothing to merge in.Tests
pages.test.ts:pagesFold.reduceover the state before, gives the same pages the command left.vequalsHANDLES[type], and there is one builder for every type inHANDLES.steps.test.ts(new):sendmakes the matching bridge call with the same arguments.pages.test.ts,blocks.test.ts,pages-store.test.ts,cli.test.ts).npm testat the root (all workspaces pass), plusnpm run typecheckandnpm run lintinapp/, all pass.PageViewis covered by the typecheck and the steps test.🤖 Generated with Claude Code