Skip to content

Instantly share code, notes, and snippets.

@OtavioBraga
Last active October 22, 2018 14:45
Show Gist options
  • Save OtavioBraga/22b06c3138eb91a88e682224db7ec2bf to your computer and use it in GitHub Desktop.
Save OtavioBraga/22b06c3138eb91a88e682224db7ec2bf to your computer and use it in GitHub Desktop.
import { eventChannel, END } from 'redux-saga'
function getWsChannel(websocket) {
// Devemos retornar o channel pois é
// nele que iremos buscar os eventos emitidos
return eventChannel(emitter => {
websocket.onmessage = event => {
emit(event.data)
}
// O channel tem um método close
// que executa esta função ao ser chamado
return () => {
websocket.close()
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment