Answer the question
In order to leave comments, you need to log in
What is the best way to design an eventChannel to receive data from a chat?
I'm using redux-saga, there are channels I accept wrapped in eventChannel
const initSocketChannel = () => eventChannel(emitter => {
socket.on('message', (msg) => {
const dataEmmit = {value: msg, type: 'message'}
emitter(dataEmmit)
})
socket.on('join room', (msg) => {
const dataEmmit = {value: msg, type: 'join room'}
emitter(dataEmmit)
})
socket.on('leave room', (msg) => {
const dataEmmit = {value: msg, type: 'leave room'}
emitter(dataEmmit)
})
socket.on('writing', (msg) => {
const dataEmmit = {value: msg, type: 'writing'}
emitter(dataEmmit)
})
// функция отписки от канала
return () => {
}
})
export const broadcastSaga = function* () {
const channel = yield call(initSocketChannel)
while (true) {
const message = yield take(channel)
console.log(message)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question