qiniu / formstate-x

Manage state of form with ease.
https://qiniu.github.io/formstate-x
MIT License
34 stars 10 forks source link

How to ensure always dispose formstate when necessary #18

Closed lzfee0227 closed 2 years ago

lzfee0227 commented 4 years ago

sth like:

new FormState(initValue, disposer)

or

https://github.com/mobxjs/mobx-react/issues/561

or sth else

FYI:

https://mobx.js.org/best/pitfalls.html#always-dispose-reactions

nighca commented 4 years ago

It can be another question: in which cases should we dispose FormState / FieldState?

lzfee0227 commented 4 years ago

https://mobx.js.org/best/pitfalls.html#always-dispose-reactions

It can be another question: in which cases should we dispose FormState / FieldState?

image

case: use global store in validators? (will use autorun in formstate-x)

@nighca

nighca commented 4 years ago

case: use global store in validators?

And in the predict function of disableValidationWhen.

nighca commented 2 years ago

With change of v3.x—as we stated in #40

https://github.com/qiniu/formstate-x/issues/18 will partly benefit from this: fields of array form state will always be correctly disposed as we manipulate them inside of formstate-x only.

We no longer need to worry about dispose for child states. The remaining problem is: how to ensure the root state correctly disposed.

Actually it is almost the same problem as: how to ensure a MobX store correctly disposed.

Just like the latter one mostly solved with tools like useLocalStore, the previous one can be mostly solved with tools like useFormstateX

nighca commented 2 years ago

Actually it is almost the same problem as: how to ensure a MobX store correctly disposed.

Since it turns out to be a problem not about formstate-x, but about MobX store. I will close this issue.