annoy.js 604 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { createReducerObject } from 'create-reducer-object';
  2. import {
  3. ANNOYED,
  4. ANNOY_RESPONDED
  5. } from 'constants/actions';
  6. const initialState = {
  7. loading: false,
  8. error: false
  9. };
  10. function onAnnoy(state) {
  11. if (state.loading) {
  12. return {};
  13. }
  14. return {
  15. loading: true,
  16. error: false
  17. };
  18. }
  19. function onAnnoyed(state, { err }) {
  20. return {
  21. loading: false,
  22. error: Boolean(err)
  23. };
  24. }
  25. const reducerMap = {
  26. [ANNOYED]: onAnnoy,
  27. [ANNOY_RESPONDED]: onAnnoyed
  28. };
  29. export const annoy = createReducerObject(reducerMap, initialState);