feat(nanoviews): expose swap_, the block if_ and switch_ are built on - #203
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #203 +/- ##
=======================================
Coverage 85.29% 85.29%
=======================================
Files 140 141 +1
Lines 3168 3168
Branches 593 593
=======================================
Hits 2702 2702
Misses 335 335
Partials 131 131 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
dangreen
force-pushed
the
feat/nanoviews-swap-block
branch
from
August 19, 2026 21:14
c89e882 to
fa22dfe
Compare
…ilt on `swap_($value, value => Child)` renders a child decided by a value and builds it anew whenever that value changes. It is what other libraries reach for `<Dynamic>` or `<component :is>` to do, except the decider returns arbitrary children instead of a component - there is no tag position to fill here, so rendering a component chosen at runtime is just calling it. The name says the part consumers get wrong: unlike a binding, which updates content in place, the block replaces it, and everything the old content held goes with it. `if_` and `switch_` are specialisations and now call it too. Internally `reactiveDecide` becomes `swap` - one name for one thing. The flow specs also stop naming their group `logic`, which never matched the directory.
dangreen
force-pushed
the
feat/nanoviews-swap-block
branch
from
August 19, 2026 21:16
fa22dfe to
6440225
Compare
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.
if_andswitch_were both built on an internal block that renders whatever a decider returns for a value, and rebuilds it when the value changes. That block is useful on its own, so it becomes public asswap_.Why not
dynamicThis is the job other libraries hand to
<Dynamic component={X} {...props}/>or<component :is>, and the todo entry that started this called it exactly that. But those exist because in JSX and in templates the tag position is not an expression — you cannot write "call this function with these props", so a component has to be smuggled in as a prop and the rest spread over it. There is no tag position here: a component is a plain function, andComp(props)already is what<Dynamic>is for. A wrapper with that signature would re-implement function application, and it would be weaker — with a decider the props are built per value, inside the closure, which one props object cannot do.So
swap_is the general block andDynamicis one line of it. Naming it after the narrow case would have promised a signature the library does not need.Why
swap_The name carries the thing consumers get wrong. A binding updates content in place; this block replaces it — the old subtree is destroyed and everything it held goes with it.
decidesaid a decision happens and stayed silent about that, which is the half people learn by losing state.The trailing
_follows the flow vocabulary —if_,for_,switch_,case_,each_— where it marks the DSL rather than dodging a keyword.What moved
internals/flow/decide.ts→internals/flow/swap.ts;reactiveDecide→swap, and the parameters lose the conditional vocabulary ($condition/decider→$value/render) now that the block is not only about conditions.flow/swap.tsasswap_;if_andswitch_call it.Cost: 10 B gzip on the all-publics bundle for the new export.
Average usageis unchanged; nothing that does not importswap_pays for it.One correction rides along, in the specs of the directory this touches: the flow specs called their group
logic, which has never matched the directory.