Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("must raises an error when pass EventChannel", () => {
const myEventChannel = eventChannel(emitter => () => {});
const myAction = { type: "test" };
// $ExpectError: event channel hasn"t a put() property
putResolve(myEventChannel, myAction);
});
function matchEventChannel(runner: MatchRunner) {
return eventChannel((emit) => {
const onFinished = runner.matchControl.on(PwEvents.GameFinished);
// TODO: how to get errors? this is not really the ideal way
const onError = runner.serverRunner.onError;
const completeHandler = () => emit('complete');
const errorHandler = (err: Error) => emit(err);
onFinished.subscribe(completeHandler);
onError.subscribe(errorHandler);
const unsubscribe = () => {
onFinished.unsubscribe(completeHandler);
onError.unsubscribe(errorHandler);
};
return unsubscribe;
responseType,
clientId,
redirectUri,
scope,
onSuccess = noop,
onFailure = noop
}
}) {
const authWindow = yield call(
window.open,
`${OAuthURI}?response_type=${responseType}&client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scope}`,
'_auth',
'width=550px,height=650px'
);
const windowEventChannel = eventChannel(emitter => {
function handleEvent(e) {
if (e.data.OAuthToken || e.data.error) {
emitter({
OAuthToken: e.data.OAuthToken,
error: e.data.error,
errorDescription: e.data.errorDescription
});
emitter(END);
}
}
window.addEventListener('message', handleEvent, false);
return () => {
// unsubscribe
window.removeEventListener('message', handleEvent);
export default function (bundle, deps) {
bundle.addReducer('init', function (state, _action) {
return state
.set('mainViewGeometry', mainViewGeometries[0])
.set('panes', Immutable.Map());
});
bundle.defineAction('windowResized', 'Window.Resized');
// Event channel for resize events.
// Only the most recent event is kept in the buffer.
const resizeMonitorChannel = eventChannel(function (listener) {
function onResize () {
const width = window.innerWidth;
const height = window.innerHeight;
listener({width, height});
}
window.addEventListener('resize', onResize);
// Add an initial event to the channel.
onResize();
return function () {
window.removeEventListener('resize', onResize);
};
}, buffers.sliding(1));
// Lift resize events into windowResized actions.
bundle.addSaga(function* monitorResize () {
while (true) {
function* createBlockMinedEventChannel(provider) {
return eventChannel(emit => {
provider.on('block', blockNumber => {
emit(blockNumber);
});
return () => {
provider.removeAllListeners('block');
};
});
}
function createPendenciesChannel(id: string) {
return eventChannel((emit) => {
return PendenciesRestService.getInstance().subscribeDocument(id, (changes: any) => {
emit(changes);
});
});
}
function createBillsChannel(filter: [string, string, string]) {
return eventChannel((emit) => {
return BillsRestService.getInstance().subscribe((changes: any) => {
emit(changes);
}, filter);
});
}
function createLoadChannel(data: ArrayBuffer) {
return eventChannel(emitter => {
function onProgress(message: string) {
emitter({
type: "progress",
message
});
}
parseSave(data, onProgress)
.then(saveGame => {
emitter({
type: "success",
saveGame
});
emitter(END);
})
.catch(error => {