redux-saga/effects#select JavaScript Examples

The following examples show how to use redux-saga/effects#select. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StartupSagas.js    From Alfredo-Mobile with MIT License 6 votes vote down vote up
// process STARTUP actions
export function * startup (api, action) {
  const user = yield select(SessionSelectors.selectUser)
  if (user) {
    api.api.setHeaders({
      'X-AUTH-TOKEN': `Bearer ${user.token}`
    })

    yield put(SessionsActions.getProfileRequest())
  }
}
Example #2
Source File: assignments.js    From agenda with MIT License 6 votes vote down vote up
export function* submitAssignmentData() {
    const assignment = yield select(state => state.assignments.assignment);
    const result = yield call(AssignmentsService.submitAssignment, assignment);
    if (result.success) {
        yield put(
            submitAssignmentDataSucceded()
        );
    }
}
Example #3
Source File: saga.js    From QiskitFlow with Apache License 2.0 6 votes vote down vote up
export function* getRuns() {
  const parameters = yield select(makeSelectExperimentRunsListFilter());
  const page = yield select(makeSelectExperimentRunsListPage());
  const experimentId = yield select(makeSelectExperimentRunsListExperimentId());
  const offset = 10 * (page - 1);
  const limit = 10;
  const requestUrl = `${getBaseUrl()}/api/v1/core/runs/?experiment=${experimentId}&offset=${offset}&limit=${limit}`;
  const token = localStorage.getItem('token');

  try {
    const response = yield call(request, requestUrl, {
      headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer ${token}`,
      },
    });
    yield put(updateRunsAction({ ...response, page }));
  } catch (err) {
    if (err.response.status === 401) {
      yield put(logoutAction());
    } else {
      yield put(repoLoadingError(err));
    }
  }
}
Example #4
Source File: sagas.js    From amazon-next with MIT License 6 votes vote down vote up
export function* cart({ payload }) {
    const { product } = payload;

    const products = yield select(state => state.cart.products);
    const productExists = products.find(
        cartProduct => cartProduct.id === payload.product.id
    );

    if (product && !productExists) {
        return yield put(addToCartSuccess(product));
    }
    return yield put(addToCartFailure());
}
Example #5
Source File: appstate.js    From haven with MIT License 6 votes vote down vote up
function* notifyServer() {
  const peerID = yield select(getUserPeerID);
  try {
    const body = yield call(resolveIpns);
    yield call(ingestPeer, peerID, body);
  } catch (err) {
    console.log('ingesting peer failed: ', err);
  }
}
Example #6
Source File: settingsSagas.js    From NextcloudDuplicateFinder with GNU Affero General Public License v3.0 6 votes vote down vote up
function * changeFilter (event) {
  if (event && event.payload && event.payload.action.startsWith('filter_')) {
    const viewData = yield select((state) => 'SettingsView' in state.app.views ? state.app.views.SettingsView : {})
    if (event.payload.action === 'filter_builder_save') {
      const savedFilter = viewData && viewData.filter ? viewData.filter.map((g) => g.conditions) : []
      yield saveSetting('ignored_files', savedFilter, viewData.filter)
    } else {
      viewData.filter = handleFilter(event.payload, viewData.filter)
      yield setViewData('SettingsView', { ...viewData })
    }
  }
}
Example #7
Source File: logger.js    From jc-calendar with MIT License 6 votes vote down vote up
export function* watchAndLog() {
  while (true) {
    const action = yield take('*');
    const stateAfter = yield select();

    console.groupCollapsed('Ran action', action.type);
    console.log({ action, stateAfter });
    console.groupEnd();
  }
}
Example #8
Source File: sagas.js    From gobench with Apache License 2.0 6 votes vote down vote up
export function * CANCEL ({ payload }) {
  const { id, data } = payload
  const state = yield select()
  const { list } = state.application
  yield loading(true)
  const response = yield call(cancel, id, data)
  if (response) {
    yield put({
      type: 'application/SET_STATE',
      payload: {
        list: list.map(x => {
          if (x.id === response.id) {
            return response
          }
          return x
        }),
        detail: response
      }
    })
    notification.success({
      message: 'Application canceled',
      description: 'You have successfully canceled an application!'
    })
  }
  yield loading(false)
}
Example #9
Source File: app.js    From full-stack-fastapi-react-postgres-boilerplate with MIT License 6 votes vote down vote up
/**
 * Switch Menu
 *
 * @param {Object} action
 *
 */
export function* switchMenu({ payload }) {
  try {
    const repos = yield select(state => state.github.repos);

    /* istanbul ignore else */
    if (!repos.data[payload.query] || !repos.data[payload.query].length) {
      yield put({
        type: ActionTypes.GITHUB_GET_REPOS,
        payload,
      });
    }
  } catch (err) {
    /* istanbul ignore next */
    yield put({
      type: ActionTypes.EXCEPTION,
      payload: err,
    });
  }
}
Example #10
Source File: categories.sagas.js    From horondi_admin with MIT License 6 votes vote down vote up
export function* handleDeleteCategory() {
  try {
    yield put(setCategoryLoading(true));
    const { switchId, deleteId } = yield select(
      selectCategorySwitchAndDeleteId
    );
    const category = yield call(deleteCategoryById, deleteId, switchId);

    if (category) {
      yield put(removeCategoryFromStore(deleteId));
      yield put(setCategoryLoading(false));
      yield call(handleSuccessSnackbar, SUCCESS_DELETE_STATUS);
    }
  } catch (error) {
    yield call(handleCategoryError, error);
  }
}
Example #11
Source File: StartupSagas.js    From gDoctor with MIT License 6 votes vote down vote up
// process STARTUP actions
export function * startup (action) {
  if (__DEV__ && console.tron) {
    // straight-up string logging
    console.tron.log('Hello, I\'m an example of how to log via Reactotron.')

    // logging an object for better clarity
    console.tron.log({
      message: 'pass objects for better logging',
      someGeneratorFunction: selectAvatar
    })

    // fully customized!
    const subObject = { a: 1, b: [1, 2, 3], c: true }
    subObject.circularDependency = subObject // osnap!
    console.tron.display({
      name: '? IGNITE ?',
      preview: 'You should totally expand this',
      value: {
        '?': 'Welcome to the future!',
        subObject,
        someInlineFunction: () => true,
        someGeneratorFunction: startup,
        someNormalFunction: selectAvatar
      }
    })
  }
  const avatar = yield select(selectAvatar)
  // only get if we don't have it yet
  if (!is(String, avatar)) {
    yield put(GithubActions.userRequest('GantMan'))
  }
}
Example #12
Source File: saga.js    From bank-client with MIT License 6 votes vote down vote up
export function* logout() {
  const { accessToken } = yield select(makeSelectToken());
  const requestURL = api.auth.logout;
  const requestParameters = {
    method: 'PATCH',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
      Authorization: `Bearer ${accessToken}`,
    },
  };

  try {
    yield call(request, requestURL, requestParameters);
    yield put(logoutSuccessAction());
    yield put(push(routes.home.path));
  } catch (error) {
    yield put(logoutErrorAction(error));

    switch (error.statusCode) {
      case 401:
        yield put(push(routes.home.path));
        break;
      default:
        yield put(push(routes.login.path));
        break;
    }
  }
}
Example #13
Source File: index.js    From stayaway-app with European Union Public License 1.2 6 votes vote down vote up
export function* setInfectionStatus({ payload: infectionStatus }) {
  const status = yield select(getStatus);

  let { errors } = status;
  if (infectionStatus === INFECTION_STATUS.INFECTED) {
    errors = [];
  };

  yield put(accountActions.updateStatus({
    ...status,
    infectionStatus,
    errors,
  }));
}
Example #14
Source File: appstate.js    From haven with MIT License 5 votes vote down vote up
function* publishData() {
  const { username, password } = yield select(getUserCredentails);
  yield call(publish, username, password);
}