Open fzyzcjy opened 2 years ago
I prefer not to mix lifecycle management of resources with core observables. Computed never holds a value, but only depends on other value holding observables. So fundamentally it's bringing irrelevant responsibility. Would not vote for this.
You are bringing application level concepts here. Don't think it's the right place. Can you see if you can solve at the application layer?
@pavanpodila Thanks for the reply! I agree and will not write code for the @computedDisposable
. However, IMHO https://github.com/mobxjs/mobx.dart/issues/857 is still very much needed. (I guess your comment is only against @computedDisposable
, not #857, but anyway I would write down some explanations)
The reason is that, sometimes the computed value is heavy. It can be a big controller that has a dispose
method, a big object (memory-hungry) that needs to be disposed (freed) when no longer needed, etc. In such cases, it would be necessary to provide that disposeValue
callback in #857.
Indeed, I have tried to implement it without modifying mobx source code, but all failed. (If you are interested I can post my non-working solution here).
@pavanpodila I love mobx (and use it extensively!), but I see Riverpod has some features that are so great - this is the main reason I am adding this (and planning to add others) - to make mobx have fewer shortcomings compared with riverpod! (Surely mobx has a lot of other strengths :) )
How about using an Atom to track the usage and then dispose when there are no more observers?
LGTM, I will revert it in #844
Example:
generates:
NOTE 1: Add this "disposeValue" automatically NOTE 2: Add this "dispose" function