redux-saga/effects#all TypeScript Examples
The following examples show how to use
redux-saga/effects#all.
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: sagas.ts From firebase-tools-ui with Apache License 2.0 | 6 votes |
export function* initAuth({ payload }: ActionType<typeof updateAuthConfig>) {
if (!payload) {
return;
}
yield setContext({
[AUTH_API_CONTEXT]: new AuthApi(
payload.auth.hostAndPort,
payload.projectId
),
});
yield all([
takeLatest(getType(authFetchUsersRequest), fetchAuthUsers),
takeLatest(getType(createUserRequest), createUser),
takeLatest(getType(nukeUsersRequest), nukeUsers),
takeLatest(getType(deleteUserRequest), deleteUser),
takeLatest(getType(updateUserRequest), updateUser),
takeLatest(getType(setUserDisabledRequest), setUserDisabled),
takeLatest(
getType(setAllowDuplicateEmailsRequest),
setAllowDuplicateEmails
),
takeLatest(
getType(getAllowDuplicateEmailsRequest),
getAllowDuplicateEmails
),
put(authFetchUsersRequest()),
put(getAllowDuplicateEmailsRequest()),
]);
}
Example #2
Source File: rootSaga.ts From rhub-app with MIT License | 6 votes |
export default function* rootSaga(): Generator {
return yield all([
takeLatest(CowsayTypes.LOAD_REQUEST, load),
...userSagas,
...labPolicySagas,
...labProductSagas,
...clusterSagas,
...labRegionSagas,
...labLocationSagas,
]);
}
Example #3
Source File: sagas.ts From orangehrm-os-mobile with GNU General Public License v3.0 | 6 votes |
function* setMultiAsyncStorage(action: SetMultiAction) {
try {
const initialStorageLoaded = yield select(selectStorageLoaded);
// Avoid update async storage when executing `loadAsyncStorage` when application starts
if (initialStorageLoaded.loaded) {
const keys = Object.keys(action.keyValuePairs);
yield all(
keys.map((keyName) => {
const key = <keyof Partial<StorageState>>keyName;
storage.set(key, action.keyValuePairs[key]);
}),
);
}
} catch (error) {}
}
Example #4
Source File: sagas.ts From orangehrm-os-mobile with GNU General Public License v3.0 | 6 votes |
export default function* rootSaga() {
yield all([
call(loadAsyncStorage),
call(watchSetStorageItem),
call(watchAuthActions),
call(watchLeaveUsageActions),
call(watchApplyLeaveActions),
call(watchLeaveListActions),
call(watchAssignLeaveActions),
call(watchCommonScreensActions),
call(watchPunchStatusActions),
call(watchAttendanceActions),
call(watchHelpConfigActions),
]);
}
Example #5
Source File: saga.ts From mamori-i-japan-admin-panel with BSD 2-Clause "Simplified" License | 5 votes |
export default function* rootSaga() {
yield all([fork(updateMessageSaga), fork(getMessagesSaga)]);
}
Example #6
Source File: updater.ts From marina with MIT License | 5 votes |
function* updateTxsAndUtxos(
accountID: AccountID,
network: NetworkString
): Generator<AllEffect<any>, void, any> {
yield all([txsUpdater(accountID, network), utxosUpdater(accountID, network)]);
}
Example #7
Source File: main.ts From marina with MIT License | 5 votes |
function* reset(): Generator<AllEffect<any>> {
const actionsTypes = [RESET_APP, RESET_WALLET, RESET_CONNECT, RESET_TAXI];
yield all(actionsTypes.map((type) => put({ type })));
}
Example #8
Source File: sagas.ts From waifusion-site with MIT License | 5 votes |
export default function* rootSaga(): any {
yield all([watchLoadWaifus()]);
}
Example #9
Source File: user-saga.ts From Riakuto-StartingReact-ja3.1 with Apache License 2.0 | 5 votes |
export default function* userSaga() {
yield all([fork(watchGetMembers)]);
}
Example #10
Source File: saga.ts From react-js-tutorial with MIT License | 5 votes |
export function* clearUserSession() {
yield all([call(logout), call(sentStatistic)]);
}
Example #11
Source File: rootSaga.ts From mamori-i-japan-admin-panel with BSD 2-Clause "Simplified" License | 5 votes |
export default function* rootSaga() {
yield all([
authSaga(),
adminUserSaga(),
PrefectureMessageSaga(),
feedbackSaga(),
]);
}
Example #12
Source File: sagas.ts From generator-earth with MIT License | 5 votes |
export default function* asyncSagas() {
yield all([
yield takeLatest(LIST__SUBMIT_FORM_ASYNC, submitFormAsync),
])
}
Example #13
Source File: saga.ts From mamori-i-japan-admin-panel with BSD 2-Clause "Simplified" License | 5 votes |
export default function* rootSaga() {
yield all([fork(showSuccessMessageSaga), fork(showErrorMessageSaga)]);
}
Example #14
Source File: saga.ts From mamori-i-japan-admin-panel with BSD 2-Clause "Simplified" License | 5 votes |
export default function* rootSaga() {
yield all([fork(loginSaga), fork(logoutSaga), fork(autoSignInSaga)]);
}
Example #15
Source File: saga.ts From mamori-i-japan-admin-panel with BSD 2-Clause "Simplified" License | 5 votes |
export default function* rootSaga() {
yield all([
fork(createAdminUserSaga),
fork(getAdminUsersSaga),
fork(deleteAdminUserSaga),
]);
}
Example #16
Source File: Products.saga.ts From react-native-woocommerce with MIT License | 5 votes |
export default function* watchAll() {
yield all([
fork(watchProductsQuery),
fork(watchRefetchProducts),
fork(watchProductsEndReached)
]);
}
Example #17
Source File: Checkout.saga.ts From react-native-woocommerce with MIT License | 5 votes |
export default function* watchAll() {
yield all([
fork(watchCheckoutCommand)
]);
}
Example #18
Source File: index.ts From firebase-tools-ui with Apache License 2.0 | 5 votes |
export function* rootSaga() {
yield all([fork(authSaga)]);
}
Example #19
Source File: sagas.ts From generator-earth with MIT License | 5 votes |
export default function* asyncSagas() {
yield all([
yield takeLatest(LIST__SUBMIT_FORM_ASYNC, submitFormAsync),
])
}
Example #20
Source File: sagas.ts From orangehrm-os-mobile with GNU General Public License v3.0 | 4 votes |
/**
* Check instance existence & compatibility
* @param action this param can be undefined when calling this generator from another generator
*/
function* checkInstance(action?: CheckInstanceAction) {
try {
yield openLoader();
let instanceUrl: string = yield selectInstanceUrl();
let response: Response = yield call(checkInstanceRequest, instanceUrl);
// check instance in advanced
const urls = getAbsoluteUrlsForChecking(instanceUrl);
// if user enter web system login screen url
if (
(!response.ok || !isJsonResponse(response)) &&
instanceUrl.includes('/index.php')
) {
const splitedInstanceUrl =
instanceUrl.split('/index.php')[0] + '/index.php';
const res: Response = yield call(
checkInstanceRequestWithCatch,
splitedInstanceUrl,
);
if (res.ok && isJsonResponse(res)) {
response = res;
instanceUrl = splitedInstanceUrl;
}
}
if (!response.ok || !isJsonResponse(response)) {
const effects = urls.map((url) => {
return call(checkInstanceRequestWithCatch, url);
});
const responses: Response[] = yield all(effects);
for (let i = 0; i < responses.length; i++) {
if (responses[i]?.ok && isJsonResponse(responses[i])) {
response = responses[i];
instanceUrl = urls[i];
break;
}
}
}
// check instance is legacy
if (!response.ok || !isJsonResponse(response)) {
// evaluate original URL without concat paths
urls.unshift(instanceUrl);
const effects = urls.map((url) => {
return call(checkLegacyInstanceWithCatch, url);
});
const responses: Response[] = yield all(effects);
for (let i = 0; i < responses.length; i++) {
// `/oauth/issueToken` endpoint content-type is `text/html`. Don't check isJsonResponse(response)
if (responses[i]?.ok) {
throw new InstanceCheckError(
'OrangeHRM System Is Not Supported With Mobile App.',
);
}
}
}
if (response.ok && isJsonResponse(response)) {
yield storageSetItem(INSTANCE_URL, instanceUrl);
const data = yield call([response, response.json]);
checkInstanceCompatibility(data);
checkRemovedEndpoints(data);
const usingDeprecatedEndpoints = checkDeprecatedEndpoints(data);
if (usingDeprecatedEndpoints) {
yield showSnackMessage('Please Update the Application.', TYPE_WARN);
}
yield* fetchEnabledModules();
yield put(checkInstanceFinished(false));
} else {
yield storageSetItem(INSTANCE_URL, null);
yield showSnackMessage('Invalid URL.', TYPE_ERROR);
yield put(checkInstanceFinished(true));
}
} catch (error) {
yield storageSetItem(INSTANCE_URL, null);
yield put(checkInstanceFinished(true));
const netState: NetInfoState = yield NetInfo.fetch();
if (netState?.isInternetReachable === false) {
const message = 'Connection Error! OrangeHRM System Is Not Accessible.';
if (action) {
yield showSnackMessage(message, TYPE_ERROR);
} else {
throw new InstanceCheckError(message);
}
} else {
if (action) {
let message = 'OrangeHRM System Is Not Accessible.';
if (error instanceof InstanceCheckError) {
message = error.message;
}
yield showSnackMessage(message, TYPE_ERROR);
} else {
throw error;
}
}
} finally {
yield closeLoader();
}
}
Example #21
Source File: sagas.test.ts From firebase-tools-ui with Apache License 2.0 | 4 votes |
describe('Auth sagas', () => {
describe('authFetchUsers', () => {
it('dispatches authFetchUsersSuccess action with the resulting info', () => {
const gen = fetchAuthUsers();
const fakeAuthApi = { fetchUsers: jest.fn() };
const fakeUsers: AuthUser[] = [];
expect(gen.next()).toEqual({
done: false,
value: call(configureAuthSaga),
});
expect(gen.next(fakeAuthApi)).toEqual({
done: false,
value: call([fakeAuthApi, 'fetchUsers']),
});
expect(gen.next(fakeUsers)).toEqual({
done: false,
value: put(authFetchUsersSuccess(fakeUsers)),
});
expect(gen.next().done).toBe(true);
});
});
describe('createUser', () => {
it('dispatches createUserSuccess', () => {
const user = { displayName: 'lol' } as AddAuthUserPayload;
const fakeAuthApi = { createUser: jest.fn() };
const gen = createUser(createUserRequest({ user }));
expect(gen.next()).toEqual({
done: false,
value: call(configureAuthSaga),
});
expect(gen.next(fakeAuthApi as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: put(setAuthUserDialogLoading(true)),
});
expect(gen.next()).toEqual({
done: false,
value: call([fakeAuthApi, 'createUser'], user),
});
expect(gen.next(user as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: put(createUserSuccess({ user: user as unknown as AuthUser })),
});
expect(gen.next()).toEqual({
done: false,
value: put(clearAuthUserDialogData()),
});
expect(gen.next()).toEqual({
done: false,
value: put(setAuthUserDialogLoading(false)),
});
expect(gen.next().done).toBe(true);
});
it('makes a separate call to update customAttributes', () => {
const user = {
displayName: 'lol',
customAttributes: '{"a": 1}',
} as AddAuthUserPayload;
const fakeAuthApi = {
createUser: jest.fn(),
updateUser: jest.fn(),
};
const gen = createUser(createUserRequest({ user }));
expect(gen.next()).toEqual({
done: false,
value: call(configureAuthSaga),
});
expect(gen.next(fakeAuthApi as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: put(setAuthUserDialogLoading(true)),
});
expect(gen.next()).toEqual({
done: false,
value: call([fakeAuthApi, 'createUser'], user),
});
const newUser = {
localId: 'lol',
displayName: user.displayName,
} as AuthUser;
expect(gen.next(newUser as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: call([fakeAuthApi, 'updateUser'], {
localId: newUser.localId,
customAttributes: user.customAttributes,
}),
});
newUser.customAttributes = user.customAttributes;
expect(gen.next(newUser as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: put(createUserSuccess({ user: newUser })),
});
expect(gen.next()).toEqual({
done: false,
value: put(clearAuthUserDialogData()),
});
expect(gen.next()).toEqual({
done: false,
value: put(setAuthUserDialogLoading(false)),
});
expect(gen.next().done).toBe(true);
});
it('handles errors', () => {
const user = { displayName: 'lol' } as AddAuthUserPayload;
const errorMessage = 'ops';
const fakeAuthApi = {
createUser: jest.fn(),
};
const gen = createUser(createUserRequest({ user }));
expect(gen.next()).toEqual({
done: false,
value: call(configureAuthSaga),
});
expect(gen.next(fakeAuthApi as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: put(setAuthUserDialogLoading(true)),
});
expect(gen.next()).toEqual({
done: false,
value: call([fakeAuthApi, 'createUser'], user),
});
gen.throw(new Error(errorMessage));
expect(gen.next()).toEqual({
done: false,
value: put(setAuthUserDialogLoading(false)),
});
expect(gen.next().done).toBe(true);
});
it('does not close the dialog', () => {
const user = { displayName: 'lol' } as AddAuthUserPayload;
const errorMessage = 'ops';
const fakeAuthApi = {
createUser: jest.fn(),
};
const gen = createUser(createUserRequest({ user, keepDialogOpen: true }));
expect(gen.next()).toEqual({
done: false,
value: call(configureAuthSaga),
});
expect(gen.next(fakeAuthApi as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: put(setAuthUserDialogLoading(true)),
});
expect(gen.next()).toEqual({
done: false,
value: call([fakeAuthApi, 'createUser'], user),
});
gen.throw(new Error(errorMessage));
expect(gen.next()).toEqual({
done: false,
value: put(setAuthUserDialogLoading(false)),
});
expect(gen.next().done).toBe(true);
});
});
describe('initAuth', () => {
it('does nothing if auth is disabled', () => {
const gen = initAuth(updateAuthConfig(null));
expect(gen.next({})).toEqual({
done: true,
});
});
it('dispatches appropriate actions if auth is enabled', () => {
const gen = initAuth(
updateAuthConfig({
auth: {
hostAndPort: 'localhost:9099',
host: 'localhost',
port: 9099,
},
projectId: 'hello',
})
);
expect(gen.next()).toEqual({
done: false,
value: setContext(expect.anything()),
});
expect(gen.next()).toEqual({
done: false,
value: all(
expect.arrayContaining([
put(authFetchUsersRequest()),
put(getAllowDuplicateEmailsRequest()),
])
),
});
expect(gen.next()).toEqual({
done: true,
});
});
});
describe('deleteUser', () => {
it('dispatches deleteUserSuccess action with the resulting info', () => {
const localId = 'pirojok';
const fakeAuthApi = { deleteUser: jest.fn() };
const payload = { localId };
const gen = deleteUser(deleteUserRequest(payload));
expect(gen.next()).toEqual({
done: false,
value: call(configureAuthSaga),
});
expect(gen.next(fakeAuthApi as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: call([fakeAuthApi, 'deleteUser'], payload),
});
expect(gen.next(payload as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: put(deleteUserSuccess(payload)),
});
expect(gen.next().done).toBe(true);
});
});
describe('updateUser', () => {
it('dispatches updateUserSuccess action with the resulting info', () => {
const localId = 'pirojok';
const user = { displayName: 'lol' } as AddAuthUserPayload;
const fakeAuthApi = { updateUser: jest.fn() };
const newUser = { ...user, localId };
const gen = updateUser(updateUserRequest({ user, localId }));
expect(gen.next()).toEqual({
done: false,
value: call(configureAuthSaga),
});
expect(gen.next(fakeAuthApi as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: put(setAuthUserDialogLoading(true)),
});
expect(gen.next()).toEqual({
done: false,
value: call([fakeAuthApi, 'updateUser'], newUser),
});
expect(gen.next(newUser as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: put(updateUserSuccess({ user: newUser as AuthUser })),
});
expect(gen.next()).toEqual({
done: false,
value: put(clearAuthUserDialogData()),
});
expect(gen.next(fakeAuthApi as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: put(setAuthUserDialogLoading(false)),
});
expect(gen.next().done).toBe(true);
});
});
describe('setUserDisabled', () => {
it('dispatches updateUserSuccess action with the resulting info', () => {
const localId = 'pirojok';
const fakeAuthApi = { updateUser: jest.fn() };
const isDisabled = true;
const payload = { disabled: isDisabled, localId };
const gen = setUserDisabled(setUserDisabledRequest(payload));
expect(gen.next()).toEqual({
done: false,
value: call(configureAuthSaga),
});
expect(gen.next(fakeAuthApi as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: call([fakeAuthApi, 'updateUser'], {
disableUser: isDisabled,
localId,
}),
});
expect(gen.next()).toEqual({
done: false,
value: put(setUserDisabledSuccess(payload)),
});
expect(gen.next().done).toBe(true);
});
});
describe('nukeUsers', () => {
it('dispatches nukeUsersSuccess action', () => {
const gen = nukeUsers();
const fakeAuthApi = { nukeUsers: jest.fn() };
expect(gen.next()).toEqual({
done: false,
value: call(configureAuthSaga),
});
expect(gen.next(fakeAuthApi as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: call([fakeAuthApi, 'nukeUsers']),
});
expect(gen.next()).toEqual({
done: false,
value: put(nukeUsersSuccess()),
});
expect(gen.next().done).toBe(true);
});
});
describe('setAllowDuplicateEmails', () => {
it('triggers appropriate API endpoint', () => {
const fakeAuthApi = { updateConfig: jest.fn() };
const gen = setAllowDuplicateEmails(setAllowDuplicateEmailsRequest(true));
expect(gen.next()).toEqual({
done: false,
value: call(configureAuthSaga),
});
expect(gen.next(fakeAuthApi as unknown as AuthApi & AuthUser)).toEqual({
done: false,
value: call([fakeAuthApi, 'updateConfig'], true),
});
expect(gen.next()).toEqual({
done: false,
value: put(setAllowDuplicateEmailsSuccess(true)),
});
});
});
describe('getAllowDuplicateEmails', () => {
it('triggers appropriate API endpoint', () => {
const fakeAuthApi = { getConfig: jest.fn() };
const gen = getAllowDuplicateEmails();
expect(gen.next()).toEqual({
done: false,
value: call(configureAuthSaga),
});
expect(gen.next(fakeAuthApi as unknown as AuthApi & boolean)).toEqual({
done: false,
value: call([fakeAuthApi, 'getConfig']),
});
expect(gen.next(false as unknown as AuthApi & boolean)).toEqual({
done: false,
value: put(setAllowDuplicateEmailsSuccess(false)),
});
});
});
describe('configureAuthSaga', () => {
it('returns api', () => {
const gen = configureAuthSaga();
expect(gen.next()).toEqual({
done: false,
value: getContext(AUTH_API_CONTEXT),
});
const fakeAuthApi = { getConfig: jest.fn() };
expect(gen.next(fakeAuthApi)).toEqual({
done: true,
value: fakeAuthApi,
});
});
});
});