How to verify if a microstate has transitioned
epikhighs opened this issue · 5 comments
Just curious. Is it possible to verify if two microstates are the same w/o doing a === check? I'm thinking of the use case while triaging a bug (or maybe even in a tool like redux dev tool), I might try to manually compare two microstates and try to figure out if a transition did occur or did not occur.
Typically, I'd think something like this would be implemented w/ a unique ID for each microstate created. So for a given microstate A and microstate B, if I inspect that the ID is the same, then I know they're the same.
Currently, in code, the best way is to do the ===
check. The JavaScript reference is, in effect, the unique Id of the microstate.
But, if I understand correctly, this would for debugging purposes where you could look in the debugger or in the console and use your eyeballs to tell if two microstates were equivalent?
If so, we probably could do this in the Store, by giving the IdType
a unique id.
Right, for example, I'd be inspecting two (or more) microstates that were console.log
ed at different points in time. I wouldn't be able to do a === check after the fact.
To be honest, I'm now questioning why I don't consider checking if my redux state reference changes w/ each action dispatched. Seems like a practical thing to do when looking for easy performance gains. I guess thinking about microstates and its details made me consider something I hadn't before. So thanks :)
@epikhighs one interesting thing to consider is Microstate's Store automatically debounces no-op transitions. If you have a single store that console.logs results of transitions, your console would not log multiple microstates unless they actually changed. You can see that in this runkit.
To be honest, I'm now questioning why I don't consider checking if my redux state reference changes w/ each action dispatched. Seems like a practical thing to do when looking for easy performance gains.
Yes, this is why we bake it into Store so you get these gains for free.
I guess thinking about microstates and its details made me consider something I hadn't before.
Glad you're doing this. 👍
Thanks. Makes sense.