How to use the redux-saga.eventChannel function in redux-saga

To help you get started, we’ve selected a few redux-saga examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / redux-saga_v1.x.x / flow_v0.76.0- / test_redux-saga_1.x.x_putResolve.js View on Github external
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);
    });
github ZeusWPI / MOZAIC / planetwars / client / app / sagas / runMatch.ts View on Github external
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;
github veritone / veritone-sdk / packages / veritone-redux-common / src / modules / auth / oauthSaga.js View on Github external
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);
github France-ioi / codecast / frontend / common / resize.js View on Github external
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) {
github magmo / apps / packages / wallet / src / redux / sagas / challenge-watcher.ts View on Github external
function* createBlockMinedEventChannel(provider) {
  return eventChannel(emit => {
    provider.on('block', blockNumber => {
      emit(blockNumber);
    });

    return () => {
      provider.removeAllListeners('block');
    };
  });
}
github tsirlucas / PayIt / src / core / pendencies / pendencies.saga.ts View on Github external
function createPendenciesChannel(id: string) {
  return eventChannel((emit) => {
    return PendenciesRestService.getInstance().subscribeDocument(id, (changes: any) => {
      emit(changes);
    });
  });
}
github tsirlucas / PayIt / src / core / bills / bills.saga.ts View on Github external
function createBillsChannel(filter: [string, string, string]) {
  return eventChannel((emit) => {
    return BillsRestService.getInstance().subscribe((changes: any) => {
      emit(changes);
    }, filter);
  });
}
github RoboPhred / oni-duplicity / src / services / oni-save / saga / load-onisave.ts View on Github external
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 => {