feat(kida): add latest for the value of the source that changed last - #231
Merged
Conversation
`latest($searchQuery, $searchParam)` merges several sources into one signal that carries whichever of them changed most recently, which is what a local cell paired with a read-only one needs: typing wins over the URL, navigation wins over what was typed. The pairing is deliberate with `previous` from `@nano_kit/store`: one looks back through a single source, the other picks the freshest across several. The last source wins on the first read and whenever several sources changed since the previous read, so reading without a subscription and writing inside a `batch` both resolve by argument order. A change is a change of value, so a write of an equal value is invisible. The winner is kept rather than recomputed: losing the last subscriber purges the deps and forces the next read to recompute with nothing changed, and a util that re-picked there would flip its answer on every remount.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #231 +/- ##
=======================================
Coverage 82.75% 82.75%
=======================================
Files 98 98
Lines 2465 2465
Branches 521 521
=======================================
Hits 2040 2040
Misses 315 315
Partials 110 110 ☔ 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.
What
latest(...sources)returns a signal carrying the value of whichever source changed most recently.Typing wins over the URL, navigation wins over what was typed. It is the missing half of
previousfrom@nano_kit/store: that one looks back through a single source, this one picks the freshest across several. It lives inkida, so@nano_kit/storere-exports it too.Contract
undefinedincluded.batch, sources sharing an upstream, and reads made without a subscription.a → b → ainside one batch.Tests
Seven cases in
packages/kida/src/utils.spec.tspin every rule above. They were checked against wrong implementations rather than only against a green run:should return the last source value on the first read when it is undefinedbreakafter the first changeshould keep the value when nothing changed since the last readSize
latestcosts 60 B gzip and 52 B brotli in kida'sAll publics: 4989 → 5049 and 4604 → 4656. BothAll publicsentries are re-pinned inkidaand instore, which mirrors them through the re-export.SignalandPopular setare untouched, the util is not in those sets.Verification
kida unit tests green (87),
oxlintandtsc --noEmitclean,test:sizerun sequentially across all 13 packages with no exceedances.