Skip to content

Latest commit

 

History

History
39 lines (32 loc) · 1.12 KB

README.md

File metadata and controls

39 lines (32 loc) · 1.12 KB

Build Status dependencies Status devDependencies Status

redux-iterators

Get better composition out of your action creators with iterators.

// composedActionCreator.js
async function gueryStuff(dispatch) {
  const fetched = await fetch('sum.url.com');
  dispatch(fetchedAction(fetched));
}

function mahPromise() {
  return new Promise((resolve, reject) => {
    post('sum.other.url.com')
      .then(() => resolve({ type: 'posted.data' }));
  });
}

export function* composedActionCreator() {
  yield { type: 'foo', payload: 'bar' };
  yield queryStuff;
  yield mahPromise();
}

// store creation
const store = createStore(
  reducers,
  initialState,
  applyMiddleware(reduxIterator, reduxPromise, reduxThunk)
);

// component
dispatch(composedActionCreator());