crudSlice
crudSlice(options) โ SagaSlice
SagaSliceconst { crudSlice } from 'saga-slice-helpers';
const { sagaApi } from './myApiFile';
export default crudSlice({
name: 'todos',
sagaApi,
initialState: { done: [], incomplete: [] },
takers: {
readAll: takeLatest
},
// OR
takers: 'takeLatest' // Will apply takeLatest to all sagas
reducers: {
setByStatus: (state, todos) => {
state.done = todos.filter(t => t.status === 'done');
state.incomplete = todos.filter(t => t.status === 'incomplete');
}
},
sagas: (A) => {
[A.readAllDone]: {
saga* ({ payload: { data } }) {
if (data) {
yield put(A.setByStatus(Object.values(data)));
}
}
}
}
});Last updated
Was this helpful?