a scenario flux doesn't support

≯℡__Kan透↙ 提交于 2019-12-13 20:34:49

问题


I am using flux architecture with React and I have an issue I don't know how to handle.

I need to write a logic that will listen to dispatched action (like a store) and will trigger an action in case the payload contains a specific value.

For example, assume there is an action that dispatch "ITEM_CREATED". My component should catch this "ITEM_CREATED" event and it's payload, and check whether the payload contains correct serial number. In case the serial number is incorrect, my component should execute an action.

Implementing this logic in a store will lead to a-synchronic store, moreover, in flux I can't trigger actions from store.

A possible solution is to create a "virtual" component (with falsy render() method) that will do that logic. Such solution will force me to put this virtual component in my JSX markup, which seams like a hack or a bad workaround.

I really want to know what is the flux solution for such scenario.

Thanks


回答1:


The answer here is to back up and do everything in response to the original action, not to create a cascade of actions.

See also:

Flux Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch

Dispatching further actions when handling actions

https://github.com/facebook/flux/issues/133#issuecomment-70775063



来源:https://stackoverflow.com/questions/29677551/a-scenario-flux-doesnt-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!