mobx-state-tree
mobx-state-tree copied to clipboard
unique id for onAction/applyAction/onSnapshot/...
Feature request
Is your feature request related to a problem? Please describe.
Currently I need a lock variable for distrubuted states (same here), but this leads to race conditions, so some actions gets never applied or send to socket.
Describe the solution you'd like
When there would be some unique identifier in the serialized actions, i could filter incoming actions within onAction, so they don't get send back.
Describe alternatives you've considered
Filter with lock variable -> race conditions, when action locally called while incoming action from socket Filter with hash of serialized action -> race conditions, when same incoming action from socket at "same" time
you can use getRunnigActionContext().id to get the unique id of the currently running action (among other things)
should also work inside the "onAction" callback I think
That being said it would probably a good idea to add this context as a param to onAction directly.
I think there's no way to add the unique action id to onSnapshot though, since a single snapshot might be the result of the transaction of the application of many actions, and only get generated at the end of the outermost action
The problem with this solution is, that I can't get the action id from applyAction to copare it within onAction.
I'm having the same problem and mentioned it on a closed issue (https://github.com/mobxjs/mobx-state-tree/issues/586#issuecomment-522179484). Having tools to manage and selectively ignore patches/actions based on their source would be great.
@benkuly Are you looking for a way to send unique id into applyAction
and consume it in onAction
??
Can you describe more on exactly what you are looking for??
@benkuly Are you looking for a way to send unique id into
applyAction
and consume it inonAction
??Can you describe more on exactly what you are looking for??
Sorry, I'm not working with mobx anymore.