redux-promise-middleware-actions
redux-promise-middleware-actions copied to clipboard
Q: Is it possible to combine an array of asyncReducer?
Hello, I am having type problems when doing something like this:
const emit = (args) => new Promise(...); /* some function -- Returns Promise<DataFormat> */
const setAll = createAsyncAction('setAll', (state: DataFormat) => emit('setAll', state));
const sync = createAsyncAction('sync', () => emit('sync'));
const allActions = [
setAll,
sync,
];
const reducers = allActions.map(action => asyncReducer<string, DataFormat, unknown>(action));
// @ts-ignore -- complains of reducer returning something incompatible no matter what I tried.
const reducer: typeof reducers[0] = (state, action) => {
// Preferably I could do reducers.reduce((s, r) => r(s, action), state))
let newState = { ...state };
reducers.forEach(reducer => {
newState = reducer(newState, action);
});
return newState;
}
export default reducer;
could maybe somebody help me out here? I would like to use 6-7 async action on the same store object (set, get, update, delete, etc...)