Loving recoil so far!
It would be nice to have a way to call reset on all of the atoms in the atomFamily.
I have a form of dynamically generated inputs managed by the atomFamily state. I also have a reset button that should reset the entire form to default values. Instead of looping through my source of data to call reset on each atom, it would be nice to have an API to reset all of the atoms in a family.
@mondaychen Can I try this??
@harshilparmar sure, we'd welcome PRs! But make sure you communicate the API here before you implement the whole thing.
@davidmccabe @drarmstr can one of you confirm whether this is a valid new feature to add to atomFamily?
Sure, it would be reasonable to consider a shortcut mechanism for reseting all family state. We've seen that request from several users. Though, we would need to consider what the API looks like. It should also likely be marked as _unstable_, since we will be addressing memory management in the future, which may affect family semantics or how they are implemented.
@drarmstr Sir can you help me to get started? I couldn't find any command for setup development.
@harshilparmar we use yarn to manage dependencies. Install yarn and run yarn in the repo directory
@mondaychen Ohh Thanks!! 馃憤
@drarmstr May be also add reset to all atoms?
This would be useful when logout without closing application.
@drarmstr May be also add reset to all atoms?
This would be useful when logout without closing application.
If you want a complete fresh slate of state, you may be able to consider adding a key to <RecoilRoot> or otherwise remounting it to use a fresh context.
Would this API remove all the keys from a family? Or would it iterate through and reset all the atoms/selectors at each key?
Would this API remove all the keys from a family? Or would it iterate through and reset all the atoms/selectors at each key?
That should just be an implementation detail that affects memory consumption / scalability. When an atom is reset it reverts to the default value. If no components or other nodes are subscribing to an atom then it may be eligible to be "garbage collected" and physically removed. But, we haven't finished working through the mechanism for cleanup and managing retention when necessary for un-subscribed atoms.