feat(data): add Observe.fromKeys reactive keyed-collection combinator#145
Merged
Conversation
fromKeys(keys$, observeChild) maps an observable list of keys to an observable of per-key child values in key order. Child subscriptions are keyed by identity and reused across list changes — only added/removed keys create/dispose a child — so a value change on one child re-emits just its slot without recomputing or re-subscribing the others. Emits once every current child has yielded (synchronously when all children are synchronous); re-emits on key-list change or any child emission. This is the dynamic, keyed counterpart to fromArray / fromProperties (which combine a fixed set of observe functions). It generalizes the local `fromEntities` helper written in firefly-platform's avTimelinePayload reactive-graph refactor; that consumer can now import this instead. Peer tests cover ordered emission, per-slot re-emit with sibling reuse, key add/remove/reorder, waiting for all children, empty list, and disposal. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
e68e9d4 to
7df6ebf
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.
Description
Adds
Observe.fromKeys— a reactive keyed collection combinator:Given an observable list of keys and a factory mapping each key to a child observe function, it yields the child values in key order. Child subscriptions are keyed by
===identity and reused across list changes — only added keys create a child and only removed keys dispose one — so a value change on one child re-emits only that child's slot (siblings keep their values, no recompute, no re-subscribe). It emits once every current child has yielded a value (synchronously when all children are synchronous), and re-emits on any key-list change or child emission.This is the dynamic, keyed counterpart to the existing
fromArray/fromProperties, which combine a fixed set of observe functions; here the set of children is itself driven by an observe function of keys.Motivation
It generalizes a local
fromEntitieshelper written forfirefly-platform'savTimelinePayloadreactive-graph refactor (select the ordered entity set → one per-entity child observable → collect), so that consumer can drop the private helper and import this instead. It is the "membership set → per-entity leaf" substrate for building O(changes) reactive dependency graphs over an ECS.Tests
New
from-keys.test.ts(peer to the source): ordered emission, per-slot re-emit with sibling reuse (asserts sibling subscription count is untouched), key add / remove (disposes child) / reorder, waiting for all children before first emit, empty-list, and full disposal (keys + every child unsubscribed).pnpm run typecheck,pnpm run lint, and the fullobservesuite (176 tests) pass. Version bumped to 0.9.80 viapnpm run bump.