-
-
Notifications
You must be signed in to change notification settings - Fork 956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a migration page for "Migrating from StateNotifier to Async/Notifier" #2630
Comments
It would be great to mention in this page (or a different), that you can pass parameters to the build method (see #2628 (comment)) |
I think it's best to write a migration page "From Riverpod 1.0 to Riverpod 2.0". That's when My intention is to fill in another PR about this topic, so that I can cross reference it into #2676 and submit it. |
I'd be skeptical about the SEO of a 1=>2 page What else would you include in it? |
If I'm not mistaken, with v2 we obtained:
Overall it was a big change that justifies the deprecation of |
Hey there! Can I try and take care of this? Also, let me know if this should be put into a broader topic, i.e. migrating from v1 to v2. Once this is cleared out, I might add some commits based on what I read here. |
@lucavenir if you want there's also a bunch of documents on the rework-flow branch that would be worth starting |
This is a meta issue for tracking documentation work related to migrating from StateNotifier to Async/Notifier
Cf #2504 (comment)
Cf #1767
Cross-link this document in the Provider migration guide, in the section talking about "Use ChangeNotifierProvider at first"
cf https://github.com/rrousselGit/riverpod/pull/2676/files#r1260743192
StateNotifier.addListener
and.stream
aren't present insideNotifier
.If you want to listen to a
Notifier
, you can useproviderContainer.listen(provider)
orref.listen(provider)
.StateNotifier.debugState
no longer exists.Tests which want to interact with Notifiers should always do so by reading the provider instead of directly instantiating the Notifier by hand.
You can do
providerContainer.read(provider)
to get the current state of a provider inside tests.Document that Async/NotifierProviders do not receive a "ref" parameter.
Logic that you would typically place inside the provider should be moved to the Notifier.build method, which has access to both
ref
and potentialfamily
parameters.Cf NotifierProvider misses ref #2460
Document that the Async/Notifier type is bound to autoDispose/family features. Enabling/disabling those notifiers means you should change the subclassed notifier type:
Note: AutoDispose variants will likely disappear once Should the type difference between autoDispose and non-autoDispose providers be removed? #2576 lands
Document how Notifiers are not disposed on ref.watch/invalidate/...
As such, ref.watch(provider.notifier) never emits a new value.
This enables keeping state across provider rebuilds. For example, we can do:
This also means that instead of overriding
dispose
, notifiers should instead rely onref.onDispose
.Due to the difference in dispose life-cycle, there is no-longer a "mounted" property as a boolean wouldn't quite work.
Related features: ref.onDispose & other life-cycles listeners should offer a way to remove the listener #2668 & Support query mutation #1660
How to override "dispose"? Instead use
ref.onDispose
How to run logic after "build"
vs:
The text was updated successfully, but these errors were encountered: