-
-
Notifications
You must be signed in to change notification settings - Fork 316
Description
As we know, riverpod is quite popular these days. I have been using mobx for a long time and think it is quite good, but I also see some strengths of riverpod. Therefore, I create this thread as a brainstorm :)
One thing I think interesting is its explicit dependency shown in code. It seems like they use ref.watch(something), when mobx just read the something directly. (I am not an expert in riverpod, so please correct me if I am wrong.)
At first, I felt mobx's way is much neater and shorter, and it does give productivity. When the codebase has grown large, I sometimes also want to know what part will cause the downstream to react. In addition, IIRC once in a while it is possible to forget to put an Observer, and then everything does not react. For example, this issue can happen when doing refactor to extract some subtree of widgets into a new widget - and then forget to put an extra observer. Similar issues are, for example, when you have an Observer, and later refactor and add a LayoutBuilder/Builder/whatever - then everything inside the builder will not be reactive without an extra Observer.
So a very very naive change to mobx may be: Add ref as an argument to Observer(builder: (context, ref) => ...). For @observable, maybe enhance the codegen such that it gives some reader object that can be used like ref.watch(store.myfield). For @computed, maybe something similar (since again we use codegen).
There do exist drawbacks for the approach. For example, people using it for small projects may feel that there are extra code to be typed.