feat(nanoviews): add as_ to hand a row through a transform - #207
Merged
Conversation
A row that needs `record` has to be a block: a `const` for the transformed row, a blank line, a `return`, and the braces around them. `as_(record, $player => li()($player.$name))` makes it an expression again. It is not about `record` - the transform is any function of the row, and the row types are left unconstrained so one signature serves the readable, writable and static forms. The transformed row stays the row: a write through it still reaches the items array.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #207 +/- ##
==========================================
+ Coverage 85.29% 85.33% +0.03%
==========================================
Files 139 139
Lines 3142 3143 +1
Branches 591 591
==========================================
+ Hits 2680 2682 +2
Misses 332 332
+ Partials 130 129 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
A row that needs a transform cannot be an expression. From this repo's own weather example:
Four lines of scaffolding — the braces, the
const, the blank line, thereturn— around a body that is one expression.as_gives the expression back:The whole thing
The transform is any function of the row, not
recordspecifically. The row and index types are deliberately unconstrained, so one signature serves all three shapesfor_hands out — the writable row, the readable one, and the static one.The thing that decided this was worth having is that inference survives.
recordis itself generic, so the row type has to flow through two generic calls in a row before it reaches the callback. It does, with no type arguments written anywhere:city.$nameisWritableSignal<string>there — checked by giving it to anumberand reading the error, not by looking at it.Tests
Two, both rendering for real: a row goes through
record, the index arrives second, and a change to the array repaints; and — the one that matters — a row transformed byas_is still the row, so normalising$player.$nameinside the body writes back into the items array.Size
+17 B gzip on all publics, and nothing on the average-usage bundle:
as_is a separate export, so a consumer who does not import it does not pay for it. One brotli pin moves up a step; the rest stay.