redux-saga如何监听多个eventChannel

时间:2017-12-28 13:28:55

标签: redux-saga

我正在为聊天室订阅2个频道。代码将停留在noCacheHash="1",直到第二个频道收到新消息。然后停留在C,直到第一个频道收到新消息。

如何让2通道分开工作。

A

1 个答案:

答案 0 :(得分:0)

为什么不将观察者创建为单独的函数并将其调用两次。例如:

function * chatWatcher(chanName) {
  while(true) {
    const message = yield take(chanName);
    yield put({ type: 'chatroom/newMessage', payload: message });
  }
}

function* ChatRoomPageEnter() {
  const chanChat = yield call($stomp.eventChannel, 'ChatRoomPage', '/topic/chat');
  const chanEcho = yield call($stomp.eventChannel, 'ChatRoomPage', '/user/queue/echo');

  yield * chatWatcher(chanChat);
  yield * chatWatcher(chanEcho);
}
相关问题