Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: Is it possible to combine an array of asyncReducer? #25

Open
brumik opened this issue Dec 19, 2021 · 0 comments
Open

Q: Is it possible to combine an array of asyncReducer? #25

brumik opened this issue Dec 19, 2021 · 0 comments

Comments

@brumik
Copy link

brumik commented Dec 19, 2021

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...)

@brumik brumik changed the title Q: Is it possible to combine an array of reducers on the same store? Q: Is it possible to combine an array of asyncReducer? Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant