7
我正在使用REDX事件通道。我有一個特定的用例,當事件被觸發時,我想要getStore狀態,因爲eventChannel不是生成器函數,我不能使用Redux傳說的選擇效果。任何其他方式來實現這一目標?在正常功能/事件中使用select效果通道
我也曾嘗試導入商店並使用store.getState()
但我得到undefined,因爲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函數移動到執行其操作的傳奇。你能分享一些代碼,以便我們可以看到eventEmitter/saga正在做什麼事情嗎? – VonD
我的用例是 我需要在連接恢復時獲取最新的未讀消息,因爲我需要獲取時間戳 收到的最後一條消息,這是存儲在這樣的命令將 發送sinceDate即上一個消息時間戳,並untilDate是currentDate –