mobx-state-tree icon indicating copy to clipboard operation
mobx-state-tree copied to clipboard

unique id for onAction/applyAction/onSnapshot/...

Open benkuly opened this issue 5 years ago • 5 comments

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

benkuly avatar May 26 '19 17:05 benkuly

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

xaviergonz avatar Jun 01 '19 08:06 xaviergonz

The problem with this solution is, that I can't get the action id from applyAction to copare it within onAction.

benkuly avatar Jun 02 '19 17:06 benkuly

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.

Ghirigoro avatar Aug 19 '19 15:08 Ghirigoro

@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??

chakrihacker avatar Sep 11 '23 16:09 chakrihacker

@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??

Sorry, I'm not working with mobx anymore.

benkuly avatar Sep 11 '23 17:09 benkuly