Replies: 2 comments 2 replies
-
|
Those methods disappeared because Those functionalities are available on |
Beta Was this translation helpful? Give feedback.
-
|
@rrousselGit I'm not sure to fully understand the reason why Ref was changed to not be generic, but I can imagine it helped to make the library better and easier to maintain, and you're right that the behavior described above can be achieved through an It's just kind of a bummer that there is now no "clean" way of implementing a Right now, we have multiple codebases relying hugely on this pattern, so it effectively means we'd have to convert a ton of I understand it would be hard (and probably a bad idea) to go back in a way that Best I could tinker is using a @riverpod
AsyncValue<T> withDataCache<T>(
Ref ref,
ProviderListenable<AsyncValue<T>> source, {
Duration duration = const Duration(seconds: 10),
}) {
final currentValue = ref.watch(source);
if (currentValue is AsyncError<T>) {
return currentValue;
}
final link = ref.keepAlive();
final timer = Timer(duration, link.close);
ref.onDispose(() {
link.close();
timer.cancel();
});
return currentValue;
}
@riverpod
Future<int> _counter(Ref ref) async {
await Future.delayed(const Duration(seconds: 3));
return 42;
}
final counterProvider = withDataCacheProvider(_counterProvider); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
Several low-level methods that were previously exposed in riverpod 2, such as
.stateand.listenSelfwere very useful for creating extensions onRef, such asFutureProvidersconditional caching (based on the current AsyncValue), reloading depending on the network availability etc.In riverpod 3, the unique
Refreplaced all the previousRefs (such asFutureProviderRef), and does not expose.state,.listenSelfor other low-level methods.For example, the cache data for a specific duration extension (code given below) which was fully based on these methods exposed in the riverpod 2 API, becomes incompatible with riverpod 3, leading to a lost of several really useful applications.
Describe the solution you'd like
Re-expose
.stateand.listenSelfonRef, or provide equivalent public APIs so that extensions likeriverpod_community_extensioncan keep working without relying on internals.Describe alternatives you've considered
A possible workaround would be replacing FutureProviders by AsyncNotifiers in this case, but it does not have a strict reasoning as the caching or any other functionalities do not make the Provider modifiable, though not giving a reason for it to become a Notifier.
Additional context
riverpod_community_extensionwas designed to extend Riverpod’s API in a clean way. These methods were essential for that goal, and their removal breaks valid use cases outside Riverpod’s core.P.S. I have found that this question was already posted here but for the version 2.6.1 when these methods were deprecated, not removed. I find it pertinent though to relaunch on this question.
#3901
Beta Was this translation helpful? Give feedback.
All reactions