Coder Social home page Coder Social logo

Comments (15)

rrousselGit avatar rrousselGit commented on August 21, 2024 2

Fair.

It's becoming O(N) for dispatching and O(1) for adding/removing listeners — which is better

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024 1

I'm promoting the usage of StateNotifier instead.

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024 1

Simply make a class that holds both of your variables

class State {
  final int count;
  final bool isLoggedIn;
}

class MyNotifier extends StateNotifier<State> {
... 
} 

from riverpod.

yaymalaga avatar yaymalaga commented on August 21, 2024

That makes me wonder if you are still using Flutter's ChangeNotifier when extending a model class or if Riverpod provides its own one that you should import instead.

from riverpod.

yaymalaga avatar yaymalaga commented on August 21, 2024

Yeah, I was in fact reading the following article.

As I see it, Freezed is a perfect helper for StateNotifier, as you can now create proper events for the UI using unions. However, I haven't find myself more articles / tutorials about StateNotifier and its uses / advantages.

The problem I see for the migration is that StateNotifier logic differs from ChangeNotifier, as instead of declaring "complex" classes and handling the state there, you are now splitting the information into several pieces, as it based on the ValueNotifier idea.

Just as an example, I was taking a look at the StateProvider doxumentation code. If using a ChangeNotifier class, I would have declared both "selectedProductIdP" and "Products" directly there. However, as it now uses StateNotifier, it is split in two different providers now. I guess you could still create a class having these two elements and then override the equals method or use the equatable library, but I don't think that would be a good solution. What I mean is that it was not trivial for me how to handle these situations at first.

Furthermore, if you also include Freezed to the mix, using inmutable data is also a game-changer in how you think about the data and how you organize your code. I would really love to have more examples showing how to change your way of thinking when developing applications with these new solutions.

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024

The examples in the example folder all uses StateNotifier.
Is there anything missing that you would like to be added?

from riverpod.

yaymalaga avatar yaymalaga commented on August 21, 2024

I will take a deep look to them and open a new issue if I miss anything. Thanks!

from riverpod.

esDotDev avatar esDotDev commented on August 21, 2024

I'm not clear how to use StateNotifier is supposed to work with the common use case of having a composite model and the filtering on specific properties. Is there an example that shows that?

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024

@esDotDev The to-do example uses StateNotifer

from riverpod.

esDotDev avatar esDotDev commented on August 21, 2024

Yes but it still seems to only support dispatching one type of payload. My models look more like this:

class CounterModel extends ChangeNotifier {
  int get count1 => _count1;
  int _count1;
  set count1(int count1) {
    _count1 = count1;
    notifyListeners();
  }

  bool get isLoggedIn => _isLoggedIn;
  bool _isLoggedIn;
  set isLoggedIn(bool isLoggedIn) {
    _isLoggedIn = isLoggedIn;
    notifyListeners();
  }
}

I know I could do it with ChangeNotifierProvider, trying to understand the State equivalent.

from riverpod.

esDotDev avatar esDotDev commented on August 21, 2024

Oh my... that is pretty :D

from riverpod.

esDotDev avatar esDotDev commented on August 21, 2024

For some reason StateNotifier class does not exist, so I don't know how to implement the code snippet shown here:
image

Just a comment on the docs in general is I find they just skip over the basics of how to use it, it presents an extremely simple use case (basic change notifier), and then jumps right into advanced use cases that start mixing hooks.

Would be nice to slow down a bit and just explain, here's how you watch, here's how you select, here's how you read. Here's a few flavors of each. Then go onto more complex stuff?

from riverpod.

rrousselGit avatar rrousselGit commented on August 21, 2024

You need to import package:state_notifier
I may re-export it in Riverpod at some point. I'm not sure

Do you mind making a separate issue about the issues you found with the documentation?
I wrote both the package and the doc, so it's hard for me to know what people do not understand

from riverpod.

esDotDev avatar esDotDev commented on August 21, 2024

Sure thing, will do, thanks for the quick response as always :)

from riverpod.

esDotDev avatar esDotDev commented on August 21, 2024

#130

from riverpod.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.