This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { fetchProfile } from 'actions' | |
| const initialState = { loading: false } | |
| export const profileReducer = (state = initialState, {type, payload}) => { | |
| switch (type) { | |
| case fetchProfile.TYPE: | |
| // handling action type 'FETCH_PROFILE@ASYNC_REQUEST'. | |
| return { loading: true } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { makeAsyncActionCreator } from 'redux-toolbelt' | |
| const fetchProfile = makeAsyncActionCreator('FETCH_PROFILE') | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { makeAsyncReducer } from 'redux-toolbelt' | |
| import { getItems } from './actions' | |
| const options = { | |
| defaultData: { items: [] }, | |
| dataGetter: (state, {type, payload, meta}) => ({ items: payload }) | |
| } | |
| export const itemsReducer = makeAsyncReducer(asyncAction, options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const state = undefined | |
| asyncReducer(state, {type: '@@INIT'}) | |
| // ⇒ { | |
| // loading: false, | |
| // myData: {items: []} | |
| // } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { checkError } from './actions' | |
| export const checkErrorReducer = makeAsyncReducer(checkError, { | |
| shouldSpread: true, | |
| destroyData: false | |
| }) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { makeThunkAsyncActionCreator } from 'redux-toolbelt-thunk' | |
| import { fetchTodosFromServer } from './api' | |
| export const fetchTodos = makeThunkAsyncActionCreator('FETCH_TODOS', fetchTodosFromServer) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {composeReducers, makeReducer, makeAsyncReducer} from 'redux-toolbelt' | |
| import { updateObjectProperties } from 'redux-toolbelt-immutable-helpers' | |
| import { loadCustomers, loadOrders, loadProfile, changeUserName, logout } from './actions' | |
| export default composeReducers( | |
| { | |
| profile: makeAsyncReducer(loadProfile), | |
| customers: makeAsyncReducer(loadCustomers), | |
| orders: makeAsyncReducer(loadOrders) | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {composeReducers, makeReducer, makeAsyncReducer} from 'redux-toolbelt' | |
| import { loadCustomers, loadOrders, loadProfile, changeUserName, logout } from './actions' | |
| export default composeReducers( | |
| { | |
| profile: makeAsyncReducer(loadProfile), | |
| customers: makeAsyncReducer(loadCustomers), | |
| orders: makeAsyncReducer(loadOrders) | |
| }, | |
| makeReducer(logout, (state, {type, payload}) => ({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| impoort { makeThunkAsyncActionCreator } from 'redux-toolbelt-thunk' | |
| export const fetchTodos = makeThunkAsyncActionCreator('FETCH_TODOS', filter => fetchTodosFromServer(filter)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const FETCH_TODOS_LOADING = 'FETCH_TODOS@LOADING' | |
| export const FETCH_TODOS_SUCCESS = 'FETCH_TODOS@SUCCESS' | |
| export const FETCH_TODOS_FAILURE = 'FETCH_TODOS@FAILURE' | |