场景通量不支持 [英] a scenario flux doesn't support

查看:83
本文介绍了场景通量不支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用React的flux体系结构,但遇到了一个我不知道如何处理的问题.

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.

例如,假设有一个调度"ITEM_CREATED"的动作.我的组件应捕获此"ITEM_CREATED"事件及其有效载荷,并检查有效载荷是否包含正确的序列号.万一序列号不正确,我的组件应执行一个操作.

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.

一个可能的解决方案是创建一个虚拟"组件(使用伪造的render()方法)来执行该逻辑.这样的解决方案将迫使我将这个虚拟组件放入我的JSX标记中,这种标记看起来像是黑客入侵或不良的解决方法.

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.

谢谢

推荐答案

此处的答案是备份并做任何事情以响应原始操作,而不是创建一系列操作.

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

另请参阅:

助焊剂分配. dispatch(...):无法在调度中间进行调度

在处理操作时分派其他操作

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

这篇关于场景通量不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆