feat: DependencyState.onViewModel for VM-backed dependencies (v2.18.0) - #14
Merged
Conversation
Add `change.onViewModel<VM, T>()` so a ViewModel can declare a dependency on a `ReactiveNotifierViewModel<VM, T>` service directly, instead of the raw `ReactiveNotifier` container. Reactions now fire when the inner ViewModel mutates via `updateState`, not only when the container instance is replaced. - DependencyState.onViewModel<VM, T>() delegating to on<T>() - ReactiveNotifierViewModel.reactiveNotifier getter exposes the container - dependency subscriptions listen to the inner VM (ChangeNotifier) target - tests for setup snapshot + reaction on inner-VM updateState - docs (README) + CHANGELOG; version 2.18.0
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
Adds
change.onViewModel<VM, T>()toDependencyState, so a ViewModel can declare a dependency on a ViewModel-backed service (ReactiveNotifierViewModel<VM, T>) directly — instead of passing the rawReactiveNotifiercontainer aschange.on<T>()requires today.Why
change.on<T>()only accepts a rawReactiveNotifier. Passing a VM-backed service's container did not react to the inner ViewModel'supdateState— aReactiveNotifier<VM>container does not notify when the inner VM mutates. This makes cross-VM dependencies work ergonomically and correctly.Changes
DependencyState.onViewModel<VM, T>()— delegates toon<T>(service.reactiveNotifier, cb)with typed(previous, current).ReactiveNotifierViewModel.reactiveNotifiergetter — exposes the underlying container.ViewModelandAsyncViewModelImpl) now listen to the inner ViewModel (ChangeNotifier) target, so reactions fire onupdateState. Simple-type notifiers behave exactly as before.Tests
New group in
test/dependency_state_test.dart:ReactiveNotifierViewModelupdateStateonViewModelequivalent toon(service.reactiveNotifier)All 21 dependency tests pass. Full suite: only pre-existing golden env-mismatch failures remain (verified identical on clean
main); no non-golden regressions.Scope
Deliberately isolated to
onViewModel. Does not include any of the ReactiveInspector WIP.