Improve Consistency for Lazy Lifecycle (watched) across API#24
Merged
estherbrunner merged 8 commits intomainfrom Feb 14, 2026
Merged
Improve Consistency for Lazy Lifecycle (watched) across API#24estherbrunner merged 8 commits intomainfrom
estherbrunner merged 8 commits intomainfrom
Conversation
- Introduce CollectionChanges<T> and switch collection API to use it instead of DiffResult - Update deriveCollection and createCollection signatures to accept applyChanges: (changes: CollectionChanges<T>) and remove DiffResult - Update tests and typings to reference CollectionChanges - Add example demonstrating element-based collection integration
- Add getKeyGenerator to centralize item key creation - Replace per-file inline key config logic with getKeyGenerator - Use DEFAULT_EQUALITY instead of legacy defaultEquals across nodes - Mark collection equality as SKIP_EQUALITY for external changes - Export getKeyGenerator from types and update typings - Align store/list/collection/sensor/memo/state/task with new equality
- Rename start -> watched lifecycles for sensors and collections - Add optional watched(invalidate) callbacks to Memo and Task - Change Collection Options.createItem signature to (value) - Rename Store/List initializer parameter from initialValue to value - Update types/docs to reflect watched semantics - Bump version to 0.18.1
Switch deriveCollection to cache derived values (T[]) and track keys Build and expose values via per-item signals; maintain separate keys array Re-establish edges when keys change to keep graph in sync Align with Store/List pattern for consistent internal structure
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.
0.18.1
Added
watched(invalidate)option:createMemo(fn, { watched })accepts a lazy lifecycle callback that receives aninvalidatefunction. Callinginvalidate()marks the memo dirty and triggers re-evaluation. The callback is invoked on first sink attachment and cleaned up when the last sink detaches. This enables patterns like DOM observation where a memo re-derives its value in response to external events (e.g., MutationObserver) without needing a separate Sensor.watched(invalidate)option: Same pattern as Memo. Callinginvalidate()aborts any in-flight computation and triggers re-execution.CollectionChanges<T>type: New typed interface for collection mutations withadd?: T[],change?: T[],remove?: T[]arrays. Replaces the untypedDiffResultrecords previously used byCollectionCallback.SensorOptions<T>type: Dedicated options type forcreateSensor, extendingSignalOptions<T>with optionalvalue.CollectionChangesexport from public API (index.ts).SensorOptionsexport from public API (index.ts).Changed
createSensorparameter renamed:start→watchedfor consistency with Store/List lifecycle terminology.createSensoroptions type:ComputedOptions<T>→SensorOptions<T>. This decouples Sensor options fromComputedOptions, which now carries thewatched(invalidate)field for Memo/Task.createCollectionparameter renamed:start→watchedfor consistency.CollectionCallbackis now generic:CollectionCallback→CollectionCallback<T>. TheapplyChangesparameter acceptsCollectionChanges<T>instead ofDiffResult.CollectionOptions.createItemsignature:(key: string, value: T) => Signal<T>→(value: T) => Signal<T>. Key generation is now handled internally.KeyConfig<T>return type relaxed: Key functions may now returnstring | undefined. Returningundefinedfalls back to synthetic key generation.Removed
DiffResultremoved from public API: No longer re-exported fromindex.ts. The type remains available fromsrc/nodes/list.tsfor internal use but is superseded byCollectionChanges<T>for collection mutations.