【发布时间】:2017-04-05 16:11:03
【问题描述】:
我正在使用 redux sagas 事件通道。我有一个特定的用例,我想在事件被触发时获取存储状态,因为 eventChannel 不是生成器函数,我无法使用 redux sagas 的选择效果。还有其他方法可以实现吗?
我也尝试过导入 store 并使用 store.getState(),但由于在 store 初始化之前导入了 saga 文件,所以我无法定义。
function subscribe(socket) {
return eventChannel(emit => {
socket.subscribe(listenerTopic, {qos: 1});
socket.on('reconnection', () => {
// i need to fetch latest unread message, for that i need to get timestamp
// for last message received which is in store so the command will be to
// send sinceDate i.e last message timestamp and untilDate that is currentDate
})
}
【问题讨论】:
-
解决方案可能涉及将一些逻辑从 eventEmitter 函数转移到 saga 采取行动。你能分享一些代码,以便我们可以看到 eventEmitter / saga 正在做什么?
-
我的用例是我需要在连接恢复时获取最新的未读消息,因为我需要获取存储的最后一条消息的时间戳,因此命令将发送 sinceDate 即最后一条消息时间戳和 untilDate 是 currentDate
标签: redux-saga