feat(data): db.derive inputs overload for external observables#149
Merged
Conversation
Add a second `db.derive(inputs, compute)` shape: a fixed record of external `Observe<T>` values (e.g. service observables that don't live in the ECS) is subscribed once at the root and injected as the callback's second argument — current values, keyed like `inputs`, unwrapped `Observe<U> → U`, strongly typed. The first argument stays the read projection, so one synchronous body can fold external values and ECS reads together. The derive recomputes when any input emits OR a recorded ECS read could have changed, and withholds its first value until every input has emitted (fromProperties semantics). Inputs are static for the derive's lifetime; dynamic cases still compose with withSwitch / fromKeys. Includes version bump to 0.9.82. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Resolve observe-derive.test.ts: keep both #148's tests (resource-sum doc + dependency-set-rebuild) and this branch's inputs-overload tests. No behavioral overlap; the shared makeSource helper + Observe import auto-merged. Co-Authored-By: Claude Opus 4.8 <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.
Adds a second
db.deriveshape that folds externalObserve<T>values (values that don't live in the ECS — e.g. observables exposed by services) into a derive, alongside ECS reads.inputsis a fixed record ofObserve<T>; the callback's second argument is their current values, keyed the same and unwrappedObserve<U> → U, strongly typed (same mapping asObserve.fromProperties).fromPropertiessemantics).Observe.withSwitch/Observe.fromKeysaround the derive.Implemented by composing
Observe.fromProperties(inputs)with the existing recording-and-gate — no new machinery. The public surface is two fully-typed overloads; the hidden implementation signature usesanyin one param position only because an overloaded impl must stay callable for the typed overload (standard TS idiom; no casts, and the loosederivetype already usedany).Tests
database-read.type-test.ts): inputs unwrapped to current values,dbstill the read projection; negatives for wrong value type, unknown key, and non-Observeinput.observe-derive.test.ts): inject + dual trigger (input change and ECS read change in one body), two inputs combined with an ECS index read, cold-start withholding, structural dedupe.tsc -b+ eslint clean.Version bumped 0.9.81 → 0.9.82.
🤖 Generated with Claude Code