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

example for StreamProvider #33

Closed
logemann opened this issue Jul 5, 2020 · 9 comments · Fixed by #45
Closed

example for StreamProvider #33

logemann opened this issue Jul 5, 2020 · 9 comments · Fixed by #45
Labels
documentation Improvements or additions to documentation

Comments

@logemann
Copy link

logemann commented Jul 5, 2020

I would like to see a more detailed example with StreamProvider in the docs. I think in the flutter / firebase context, a really nice example would be the equivalent of this from the provider way of things:

StreamProvider<FirebaseUser>.value(
            value: FirebaseAuth.instance.onAuthStateChanged);

translated to River Pod, it might look like this, but i could be wrong (since i am trying to clean up here, its not 1:1 translation as is):

final firebaseAuthProvider = StreamProvider<FirebaseUser>((ref) {
  ref.onDispose(() {
    // Closes the StreamController when the state of this provider is destroyed.
    FirebaseAuth.instance.signOut();
  });

  return FirebaseAuth.instance.onAuthStateChanged;
});

Please correct me if i am wrong on this.

@logemann logemann added the documentation Improvements or additions to documentation label Jul 5, 2020
@rrousselGit
Copy link
Owner

For firebase you will want to use AutoDisposeStreamProvider, to stop the subscription ASAP when the UI doesn't use the value anymore

@logemann
Copy link
Author

logemann commented Jul 5, 2020

good hint. Wasnt aware of the class alltogether ;-)

@logemann
Copy link
Author

logemann commented Jul 5, 2020

I think it would be super nice to have little code example inside the API doc like with https://pub.dev/documentation/riverpod/latest/riverpod/StateNotifierProvider-class.html. Would speed up adoption drastically.

And to me its not clear how to handle the types when constructing the provider as well as with the caller of the hook useProvider(firebaseAuthProvider)

@AlexHartford
Copy link
Contributor

I strongly agree. I really love your libraries but it takes me some time to figure out how to use them optimally due to lack of examples. Even something simple would go a long way. That said, I plan to share some of the things I come up with.

@rrousselGit
Copy link
Owner

I'm finishing #39 first, which will make documenting providers easier.
Then I'll document all providers individually.

@rrousselGit rrousselGit linked a pull request Jul 11, 2020 that will close this issue
@AlexHartford
Copy link
Contributor

Tying together the above comments with the newly introduced syntax:

StreamProvider.autoDispose((ref) => FirebaseAuth.instance.onAuthStateChanged)

Thanks for the updates Remi!

@logemann
Copy link
Author

@AlexHartford so AutoDisposeStreamProvider is already outdated and one should use StreamProvider.autoDispose() ?

@rrousselGit
Copy link
Owner

The syntax changed a bit recently, yes.
But AutoDisposeStreamProvider and StreamProvider.autoDispose are strictly equivalent.

@logemann
Copy link
Author

logemann commented Jul 14, 2020

thanks. Just noticed that i wasnt on latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants