【发布时间】:2016-03-23 17:23:38
【问题描述】:
我有一个项目,其中 nodejs 服务器通过 socket.io 将推送事件传递到反应仪表板,我正在使用 Redux。当收到新数据时,会触发更新所有相关组件的操作,尽管我不确定我这样做的方式是否正确。
这是我监控来自服务器的新传入数据的方式:
socket.on('incidents', state => {
boundActionSetIncidentsList(state);
});
这是对新数据调用的有界动作创建者:
import { store } from '../index';
export function boundActionSetIncidentsList(incidents) {
store.dispatch(actionSetIncidentsList(incidents));
}
我需要 store 来调度动作,正如你所看到的,我粗暴地从主 index.js 导入它。它是这样创建的:
export const store = createStore();
作为 react 和 redux 的新手,我想知道 redux 调度不是从容器或展示组件触发的动作的方式是什么。谢谢!!
【问题讨论】: