Ejemplo n.º 1
0
export function* watchSetAllowanceProgress() {
	while (yield take(constants.SET_ALLOWANCE)) {
		const progressTask = yield fork(setAllowanceProgressBarSaga)
		yield take(constants.SET_ALLOWANCE_COMPLETED)
		yield cancel(progressTask)
	}
}
Ejemplo n.º 2
0
test('subscriptionWatcherCreator', t => {
  const params = {};
  const subscription = { id: 1 };
  const watcher = sagaCreators.subscriptionWatcherCreator('test', params);
  const gen = watcher();
  const subsChannel = eventChannel(() => () => {});
  const readyChannel = eventChannel(() => () => {});
  const errorChannel = eventChannel(() => () => {});
  const task = { cancel: () => {} };
  t.deepEqual(gen.next().value, call(deps.libs.collectionEventChannel, 'test'));
  t.deepEqual(gen.next(subsChannel).value, take(deps.types.LOGIN_SUCCEED));
  t.deepEqual(gen.next().value, put(actions.subscriptionStarted('test')));
  t.deepEqual(gen.next().value, call(deps.libs.subscribe, 'test', params));
  t.deepEqual(gen.next(subscription).value, call(deps.libs.readyEventChannel, subscription));
  t.deepEqual(gen.next(readyChannel).value, call(deps.libs.errorEventChannel, subscription));
  t.deepEqual(gen.next(errorChannel).value,
    fork(sagaCreators.subscriptionEvents, subsChannel, actions.subscriptionModified));
  t.deepEqual(gen.next(task).value,
    fork(sagaCreators.subscriptionEvents, readyChannel, actions.subscriptionReady));
  t.deepEqual(gen.next(task).value,
    fork(sagaCreators.subscriptionEvents, errorChannel, actions.subscriptionFailed));
  t.deepEqual(gen.next(task).value, take(deps.types.LOGOUT_SUCCEED));
  t.deepEqual(gen.next().value, call(deps.libs.unsubscribe, subscription.id));
  t.deepEqual(gen.next().value, put(actions.subscriptionStopped('test')));
  t.deepEqual(gen.next().value, take(deps.types.LOGIN_SUCCEED));
});
Ejemplo n.º 3
0
test('subscriptionEvents', t => {
  const channel = eventChannel(() => () => {});
  const action = () => ({ type: 'SOME_ACTION' });
  const result = {};
  const gen = sagaCreators.subscriptionEvents(channel, action);
  t.deepEqual(gen.next().value, take(channel));
  t.deepEqual(gen.next(result).value, put(action(result)));
  t.deepEqual(gen.next().value, take(channel));
});
Ejemplo n.º 4
0
export function* mainWatch () {
    while (true) {
        yield take((action)=> {
            return action.type == PAGE_ACTIVATE && action.payload.name == 'orders';
        });
        yield put(getTree());
        yield take(PAGE_ACTIVATE);
    }
}
Ejemplo n.º 5
0
 beforeEach(() => {
   expect(generator.next().value).toEqual(race({
     loadRepos: take(LOAD_REPOS),
     stop: take(LOCATION_CHANGE),
   }));
   expect(generator.next(take(LOAD_REPOS)).value).toEqual(select(selectUsername()));
   const requestURL = `https://api.github.com/users/${username}/repos?type=all&sort=updated`;
   expect(generator.next(username).value).toEqual(call(request, requestURL));
 });
Ejemplo n.º 6
0
function* saveSourceCode(){
    while(true){
        const { payload } = yield take(actions.SAVE_SOURCE_CODE);
        yield put(spinnerActions.started('Saving source code'));
        const saveTask = yield fork(saveComponentSourceCode, payload);
        const delayTask = yield fork(delaySaveComponentSourceCode);
        yield take([actions.SAVE_SOURCE_CODE_DONE, actions.SAVE_SOURCE_CODE_TIMEOUT]);
        yield cancel(saveTask);
        yield cancel(delayTask);
        yield put(spinnerActions.done('Saving source code'));
    }
}
Ejemplo n.º 7
0
export default function* fetchAppDataSaga(): Generator<*, *, *> {
  yield fork(doFetchRooms);
  yield fork(doFetchBeacons);
  yield fork(doFetchBookings);
  yield fork(doFetchTimeslots);

  yield put(fetchRooms());
  yield take('FETCH_ROOMS_SUCCESS');

  yield put(fetchBeacons());
  yield take('FETCH_BEACONS_SUCCESS');
}
Ejemplo n.º 8
0
export function *saga () {
  debug("starting listeners");
  let listeners = yield *forkListeners();

  // receiving & saving contracts into state
  debug("waiting for contract information");
  let { contexts, sources } = yield take(actions.RECORD_CONTRACTS);

  debug("recording contract binaries");
  yield *recordContexts(...contexts);

  debug("recording contract sources");
  yield *recordSources(...sources);

  debug("waiting for start");
  // wait for start signal
  let {txHash, provider} = yield take(actions.START);
  debug("starting");

  // process transaction
  debug("fetching transaction info");
  let err = yield *fetchTx(txHash, provider);
  if (err) {
    debug("error %o", err);
    yield *error(err);

  } else {
    debug("visiting ASTs");
    // visit asts
    yield *ast.visitAll();

    debug("readying");
    // signal that stepping can begin
    yield *ready();

    debug("waiting for trace EOT");
    // wait until trace hits EOT
    yield *trace.wait();

    debug("finishing");
    // finish
    yield put(actions.finish());
  }

  debug("stopping listeners");
  yield all(
    listeners.map(task => cancel(task))
  );
}
Ejemplo n.º 9
0
function* watchSignin() {
    while (true) {
        let action = yield take(actions.BEGIN_SIGNIN)

        yield fork(auth.sagas.signin, action.network)
        action = yield take([auth.actions.AUTH_SIGNIN_SUCCESS, auth.actions.AUTH_SIGNIN_FAILURE])

        if (action.type === auth.actions.AUTH_SIGNIN_SUCCESS) {
            yield put(push('/profile/welcome'))
        }
        else {
            //TODO: notify user 
        }
    }
}
Ejemplo n.º 10
0
function* watchSignout() {
    while (true) {
        let action = yield take(actions.BEGIN_SIGNOUT)

        yield fork(auth.sagas.signout)
        action = yield take([auth.actions.AUTH_SIGNOUT_SUCCESS, auth.actions.AUTH_SIGNOUT_FAILURE])

        if (action.type === auth.actions.AUTH_SIGNOUT_SUCCESS) {
            yield put(push('/'))
        }
        else {
            //TODO: notify user 
        }
    }
}
Ejemplo n.º 11
0
export default function* authFlowSaga() {
  // wait for gapi to load from google
  let gapiLoading = true;
  while (gapiLoading) {
    if (gapi) {
      yield call(loadCalendarApi);
      yield call(initClient);
      gapiLoading = false;
    } else {
      yield delay(1000);
    }
  }

  yield* handleAuth(
    isSignedIn(),
    'Could not automatically authenticate. Please click the button above to login.'
  );

  while (true) {
    const { type } = yield take([AUTH_REQUEST, AUTH_LOGOUT]);
    if (type === AUTH_REQUEST) {
      yield call(signIn);
      yield* handleAuth(
        isSignedIn(),
        'Authentication failed, please try again.'
      );
    } else if (type === AUTH_LOGOUT) {
      yield call(signOut);
      yield* handleAuth(isSignedIn());
    }
  }
}
Ejemplo n.º 12
0
function* receiverSaga() {
  const channel = yield call(socketEventChannel)
  try {
    while (true) { // eslint-disable-line
      // take(END) will cause the saga to terminate by jumping to the finally block
      let message = yield take(channel)
      console.log('message', message)
      if (message.type === 'open') {
        yield put({
          type: 'SOCKET_OPEN',
        })
      } else if (message.type === 'messageReceived') {
        yield put({
          type: 'SOCKET_MESSAGE_ARRIVED',
          message: message.value,
        })
      } else {
        // when error happens
        yield put({
          type: 'SOCKET_ERROR',
          error: message.value,
        })
      }
    }
  } finally {
    yield put({
      type: 'SOCKET_CLOSED',
      // message: message.value,
    })
    socketConnection.close()
  }
}
Ejemplo n.º 13
0
export function* watchForCompletedPlot(options, dispatch, getState) {


    let masterPlot;
    let plot;

    while (!masterPlot || !plot) {
        const action = yield take([ImagePlotCntlr.PLOT_IMAGE, ImagePlotCntlr.PLOT_IMAGE_FAIL]);
        const {plotId, masterPlotId, wcsMatchType}= options;

        if (action.type===ImagePlotCntlr.PLOT_IMAGE_FAIL && action.payload.plotId===plotId) {
            return;
        }
        const visRoot= getState()[IMAGE_PLOT_KEY];
        masterPlot= primePlot(visRoot, masterPlotId);
        plot= primePlot(visRoot, plotId);


        if (masterPlot && plot) {
            const masterPv= getPlotViewById(visRoot, masterPlotId);
            const pv= getPlotViewById(visRoot, plotId);
            const level = wcsMatchType===WcsMatchType.Standard  || wcsMatchType===WcsMatchType.Target ?
                masterPlot.zoomFactor :
                getEstimatedFullZoomFactor(primePlot(masterPv),masterPv.viewDim, FullType.WIDTH_HEIGHT);
            const asPerPix= getArcSecPerPix(masterPlot,level);
            if (wcsMatchType===WcsMatchType.Target) {
                const ft=  masterPlot.attributes[PlotAttribute.FIXED_TARGET];
                if (ft) dispatchRecenter({plotId:masterPv.plotId, centerPt:ft});
            }
            syncPlotToLevel(pv, masterPv, asPerPix);
            dispatchUpdateViewSize(pv.plotId);
        }
    }

}
Ejemplo n.º 14
0
function* clearStatisticsAndMemoryUsage() {
    while (true) {
        yield take(PFA_DOCUMENT_UPLOAD_SUCCESS);
        yield put(resetStatisticsAction());
        yield put(resetMemoryUsageAction());
    }
}
Ejemplo n.º 15
0
export function* login () {
  while(true) {
    console.log('in saga');
    // Wait for the REQUEST_USERS action
    //Hard coded for dev
    const info = yield take(ACTIONS.REQUEST_LOGIN);
    console.log(info);
    let formData = new FormData();
     formData.append('email', '*****@*****.**');
     formData.append('password', 'password123');
    try {
      console.log('SAGA TIME');
      const options = {
        method: 'POST',
        url: API_URL.login,
        params: formData,
      };
      // Tell redux-saga to call fetch with the specified options
      const response = yield call(apiLogin, '*****@*****.**', 'password123');
      const parseJson = yield JSON.parse(response);
      const activeUser = yield mapActiveUser(parseJson);

      yield put(loginResults(activeUser));
      const addToken = yield makeToken(activeUser.api_token);
      yield info.ctx.setState({signedIn: true, err: false, msg: `You have been logged in.`});
    }
    catch (err) {
      // Send the error
      console.log('ERRROR');
      console.log(err);
      yield put (loginResultsError(err));
      yield info.ctx.setState({err: "Wrong Username/Password" , signedIn: false});
    }
  }
}
Ejemplo n.º 16
0
function * takeFlashMessages() {
  while (DAEMON) {
    const action = yield take('flash/ADD_MESSAGE')
    log.sagas('Flash added, saga will remove it automatically')
    yield fork(timeoutRemoveFlash, action.payload)
  }
}
Ejemplo n.º 17
0
function* read(socket) {
  const channel = yield call(subscribe, socket)
  while (true) {
    let action = yield take(channel)
    yield put(action)
  }
}
Ejemplo n.º 18
0
// Watchers
function* watchLoadStations() {
  yield take(catFinderActions.LOAD_STATIONS)
  const stationData = yield call(services.fetchStationsData)
  const stations = services.prepareStations(stationData)

  yield put({type: catFinderActions.STATIONS_LOADED, stations})
}
Ejemplo n.º 19
0
export function* getRecord1Watcher() {
    while(true){
        let action = yield take(LOAD_RECORD1);
        //console.log("getShopWatcher:"+action.placeid);
        yield call(getRecord1, [action.master_id]);
    }
}
Ejemplo n.º 20
0
export default function* watchProvidersSaga() {
  // eslint-disable-next-line no-constant-condition
  while (true) {
    yield take(PROVIDERS_FETCH); // wait for PROVIDERS_FETCH event
    yield fork(fetchProviders);
  }
}
Ejemplo n.º 21
0
export function* getTodosBoot() {
  // Fork watcher so we can continue execution
  const watcher = yield fork(getTodosWatcher);

  // Suspend execution until location changes
  yield take(LOCATION_CHANGE);
  yield cancel(watcher);
}
Ejemplo n.º 22
0
export function * setActiveColumnsSaga () {
	while (true) {
		const { columns } = yield take(actions.SELECT_ACTIVE_COLUMNS);
		const { currentList } = yield select(state => state.lists);
		const newColumns = yield call(columnsParser, columns, currentList);
		yield put({ type: actions.SET_ACTIVE_COLUMNS, columns: newColumns });
	}
}
Ejemplo n.º 23
0
export function* record3Data() {
  // Fork watcher so we can continue execution
  const watcher = yield fork(getRecord3Watcher);

  // Suspend execution until location changes
  yield take(LOCATION_CHANGE);
  yield cancel(watcher);
}
Ejemplo n.º 24
0
function* watchMoveStations() {
  while(true) {
    const {catOwners} = yield take(catFinderActions.MOVE_STATIONS)
    yield call(delay, 1)
    const newOwners = services.moveStations(catOwners)
    yield put({type: catFinderActions.MOVE_COMPLETED, catOwners: newOwners})
  }
}
Ejemplo n.º 25
0
test('reset Saga test', (t) => {
  const generator = reset()

  t.deepEqual(
    generator.next().value,
    take('RESET'),
    'reset Saga wait RESET action'
  )

  t.deepEqual(
    generator.next().value,
    take('RESET'),
    'reset Saga must go back to beginning of loop'
  )

  t.end()
});
Ejemplo n.º 26
0
// Individual exports for testing
export default function* defaultSaga() {
  yield fork(takeLatest, ON_DELETE_PLUGIN_CONFIRM, deletePlugin);
  const loadPluginsWatcher = yield fork(takeLatest, GET_PLUGINS, pluginsGet);

  yield take(LOCATION_CHANGE);

  yield cancel(loadPluginsWatcher);
}
Ejemplo n.º 27
0
const watchBlogMount = function* () {

    let action;
    while (action = yield take(blogActions.GET_POSTS)) {
        const blogData = yield call(interceptData, action.url, null, null, true);
        yield put(blogActions.setPosts(blogData));
    }
};
Ejemplo n.º 28
0
const watchPostMount = function* () {

    let action;
    while (action = yield take(postActions.GET_POST)) {
        const postData = yield call(interceptData, action.url, null, null, true);
        yield put(postActions.setPost(postData));
    }
};
Ejemplo n.º 29
0
const watchDrawerToggled = function* () {

    let action;
    while (action = yield take(appActions.TOGGLE_APP_DRAWER)) {
        console.log('taken');
        yield put(appActions.getDrawerData());
    }
};
Ejemplo n.º 30
0
const watchEdition = function* () {

    let action;
    while (action = yield take(appActions.GET_DRAWER_DATA)) {
        const edition = yield call(interceptData, action.endpoint);
        yield put(appActions.setDrawerData(edition));
    }
};