refactor(act): share non-widening builder members via BuilderCore#1111
Open
Rotorsoft wants to merge 2 commits into
Open
refactor(act): share non-widening builder members via BuilderCore#1111Rotorsoft wants to merge 2 commits into
Rotorsoft wants to merge 2 commits into
Conversation
) act-builder and slice-builder duplicated the type signatures of withProjection, on, and events — the members that return the builder unchanged (Self). Extract them into a BuilderCore<Self, ...> interface both builders extend via F-bounded polymorphism, so Self resolves to the concrete SliceBuilder/ActBuilder and error messages are unaffected. SliceBuilder/ActBuilder become interfaces (the canonical form for F-bounded self-reference; a type alias circularly references itself). ~56 net lines removed. withState and withLane stay per-builder: they *widen* the generics (return a different instantiation), which a shared signature could only express with HKT emulation — and that degrades the public builder's hover/error output, a poor trade for two declarative signatures. Documented in builder-core.ts. Runtime unchanged (968 act tests, 100% coverage); public surface unchanged (interface vs alias is a source-text-only snapshot diff). The full shared base is left to follow-up per the same rationale. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…1110) Rename builder-core.ts to builder-base.ts and the type BuilderCore to BuilderBase (both builders extend it, so 'base' reads truer than 'core'). Move the ReactionOn step type from internal/builder-utils.ts into builder-base.ts so the two shared builder *types* live together in the builders layer, and drop ReactionOn from the internal barrel — the runtime helpers (reaction_on, register_lane) stay in internal. ReactionOn inlines its schedule param as DeferWhen | (event => DeferWhen) (DeferWhen is public) so it needs nothing from internal, keeping the layering clean. Bonus: ReactionOn left the (re-exported, snapshotted) internal barrel, so the stability snapshot net-shrinks — the source-text growth that tripped the RFC gate on the prior commit is gone. No behavior change (968 act tests, 100% coverage), no public surface change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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 #1110 (partial — the clean F-bounded portion; see Follow-up).
Follows the
builder-utilsextraction in #1109.act-builderandslice-builderstill duplicated the type signatures of the members that return the builder unchanged —withProjection,on,events. This extracts them into aBuilderCore<Self, …>interface both builders extend via F-bounded polymorphism.What changed
libs/act/src/builders/builder-core.ts—BuilderCore<Self, TEvents, TActions, TActor, TLanes>holdingwithProjection,on,events.Selfis the concrete builder passed by each extender, so hover/error output resolves toSliceBuilder<…>/ActBuilder<…>, not an abstract base.SliceBuilderandActBuilderbecome interfaces thatextends BuilderCore<Self, …>. Interface is the canonical form for F-bounded self-reference; atypealias= Base<Self> & {…}circularly references itself (TS2456).Why
withState/withLanestay per-builderThey widen generics (return a different instantiation), which a shared signature could only express with HKT emulation. A spike confirmed HKT works functionally but degrades the public builder's hover and error messages — a poor trade for deduping two stable declarative signatures. This is documented in
builder-core.ts, and the full shared base is left as a follow-up under the same rationale (it's the highest type-risk piece).Test plan
pnpm typecheckcleanpnpm test— 968 act tests pass (runtime unchanged; the@ts-expect-errortype-assertion tests still hold, confirming builder type behavior is identical)builder-core.tsis type-only).pnpm lintclean,pnpm buildcleanStability charter impact
Additive / none.
SliceBuilder/ActBuilderchange from type alias to interface — a source-text-only snapshot diff with identical structural surface (same members, same signatures). No export removed or narrowed.🤖 Generated with Claude Code