Skip to content
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

Expose an interface for providers with notifiers #3646

Open
CardosoShlomo opened this issue Jul 7, 2024 · 2 comments
Open

Expose an interface for providers with notifiers #3646

CardosoShlomo opened this issue Jul 7, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@CardosoShlomo
Copy link

I wish to be able to write something like ref.write(provider) or ref.notify(provider) instead of ref.read(provider.notifier)

I found that the providers that have a notifier do not have a unique supper class in common
so I wonder if we can create a class like HasNotifierProvider that extends BaseProvider and holds the notifier getter
then make AsyncNotifierProviderBase, NotifierProviderBase and _StateProviderBase extends HasNotifierProvider instead of BaseProvider and override the notifier

then I'll be able to add extensions on Ref and WidgetRef

extension on Ref {
  notify<T>(HasNotifierProvider<T> provider) => read(provider.notifier);
}
@CardosoShlomo CardosoShlomo added enhancement New feature or request needs triage labels Jul 7, 2024
@rrousselGit rrousselGit changed the title enable write extension on ref Expose an interface for providers with notifiers Jul 8, 2024
@CardosoShlomo
Copy link
Author

@rrousselGit Is there a reason why Ref and WidgetRef do not share an abstract class?

@jakeaaron
Copy link

jakeaaron commented Jul 16, 2024

@CardosoShlomo

@rrousselGit Is there a reason why Ref and WidgetRef do not share an abstract class?

To answer your question with the docs: https://riverpod.dev/docs/essentials/faq#why-is-there-no-shared-interface-between-ref-and-widgetref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants