A helper for the REQUEST/SUCCESS/FAILURE action creator pattern found in Redux.
Utilizes deox to provide strong TypeScript inferences.
Helps reduce boilerplate when making asynchronous API calls in Sagas or Thunks.
// saga.ts
function* fetchFooSaga({ meta }: ReturnType<typeof fetchFoo.trigger>) {
const { id } = meta;
try {
const foo = yield call(api, id);
yield put(fetchFoo.success(foo, meta));
} catch (error) {
yield put(fetchFoo.failure(error, meta));
}
}
export function* fooSaga() {
yield takeEvery(fetchFoo.TRIGGER, fetchFooSaga);
}
// Component.tsx
dispatch(fetchFoo.trigger({ id: '5' }))
the data to be merged into state, usually a domain object from your API
the metadata required to start a routine, for example the ID of an object
prefix for action type
Listens to all actions on the store and stores error state for every routine
// store.ts
import { errorReducer } from 'redux-routines-ts'
const rootReducer = combineReducers({
// your other reducers...
error: errorReducer,
});
const store = createStore(rootReducer, middleware)
Listens to all actions on the store and stores loading state for every routine
// store.ts
import { loadingReducer } from 'redux-routines-ts'
const rootReducer = combineReducers({
// your other reducers...
loading: loadingReducer,
});
const store = createStore(rootReducer, middleware)
Generated using TypeDoc
Creates a set of life-cycle actions that are useful for asynchronous actions like fetching data
const fetchFoo = createRoutine<Foo, { id: string }>('FETCH_FOO') const fetchAll = createRoutine<Foo[]>('FETCH_ALL_FOO')