daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { createReducer } from 'redux-act';
  2.  
  3.  
  4. import {
  5.     getUsers,
  6.     getUsersThunk,
  7.     getUsersSuccess,
  8.     getUsersFailure,
  9.     cancelFetchUsers
  10. } from '../actions/users';
  11. const initialState = {
  12.     data: [],
  13.     isFetching: false,
  14.     isCanceled: true,
  15.     error: false,
  16. };
  17.  
  18. export default createReducer({
  19.     [getUsersThunk]: state => ({ ...state, isFetching: true, isCanceled: false }),
  20.     [getUsers]: state => ({ ...state, isFetching: true, isCanceled: false }),
  21.     [getUsersSuccess]: (state, payload) => {
  22.         if (state.isCanceled) {
  23.             return state;
  24.         }
  25.  
  26.         return {
  27.             ...state,
  28.             isFetching: false,
  29.             isCanceled: false,
  30.             data: payload
  31.         };
  32.     },
  33.     [getUsersFailure]: (state, payload) => ({
  34.         ...state,
  35.         isFetching: false,
  36.         isCanceled: false,
  37.         error: payload
  38.     }),
  39.     [cancelFetchUsers]: state => ({
  40.         ...state,
  41.         data: [],
  42.         isFetching: false,
  43.         isCanceled: true,
  44.     }),
  45. }, initialState);
RAW Paste Data
Top