Last active
October 22, 2018 14:45
-
-
Save OtavioBraga/22b06c3138eb91a88e682224db7ec2bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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