Skip to content

Instantly share code, notes, and snippets.

@camwest
Created May 10, 2016 04:37
Show Gist options
  • Save camwest/66b19208ac3c7c4d7c44f5de276d680e to your computer and use it in GitHub Desktop.
Save camwest/66b19208ac3c7c4d7c44f5de276d680e to your computer and use it in GitHub Desktop.
function* watchEvents(): any {
const initial = yield call(ExternalApi.getCurrent);
yield put(receiveEvent(initial);
const chan = yield call(setupEvents);
while (true) {
const event = yield take(chan);
yield put(receiveEvent(event));
}
}
function setupEvents() {
return eventChannel(listener => {
ExternalApi.addChangeListener(listener);
return () => {
ExternalApi.removeChangeListener(listener);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment