Приложение чата с redux-сагой, блокирующее некоторые звонки - PullRequest
0 голосов
/ 29 апреля 2020

Я не могу понять, почему, если я не очищаю все строки до const historyData = yield take(onHistory); внутри while, я не могу получить эти данные из канала history. Вот сага

export default function* chatSaga({ socket }) {

  const channel = yield call(joinChannel, socket, 'chat:data');

  const onMessage = yield call(createSocketChannel, channel, "message");
  const onConversation = yield call(createSocketChannel, channel, "conversation");
  const onHistory = yield call(createSocketChannel, channel, "history");

  const onPresenceState = yield call(createSocketChannel, channel, "presence_state");
  const onPresenceDiff = yield call(createSocketChannel, channel, "presence_diff");

  while (true) {
    const messageData = yield take(onMessage)
    yield put(chat.privateMessage(messageData));

    const conversationData = yield take(onConversation)
    yield put(chat.addChannel(conversationData));

    const presenceStateData = yield take(onPresenceState)
    yield put(chat.presenceState(presenceStateData));

    const presenceDiffData = yield take(onPresenceDiff)
    yield put(chat.presenceState(presenceDiffData));

    const historyData = yield take(onHistory);
    yield put(chat.historyMessage(historyData));
  }

}

Вот импорт:

export function* joinChannel(_socket, channelName) {
    const channel = yield _socket.channel(channelName, {});
    channel.join()
        .receive("ok", (resp) => {
            console.log(`Joined successfully: ${channelName}`, resp);
        })
        .receive('error', (reason) => {
            console.log('Unable to join', { channel: channel.topic, reason });
        });

    return channel;
}

export const createSocketChannel = (channel, constant) =>
    // `eventChannel` takes a subscriber function
    // the subscriber function takes an `emit` argument to put messages onto the channel
    eventChannel((emit) => {
        const newDataHandler = (event) => {
            emit(event);
        };

        channel.on(constant, newDataHandler);

        const unsubscribe = () => {
            channel.off(constant, newDataHandler);
        };

        return unsubscribe;
    });
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...