From 8faf902b0391fb8311edc994e7acbb3769df9879 Mon Sep 17 00:00:00 2001 From: thykos Date: Mon, 10 Oct 2016 14:46:17 +0300 Subject: [PATCH] add `loading` to root store --- modules/asyncConnect.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/asyncConnect.js b/modules/asyncConnect.js index a6b86b96..c36e5354 100644 --- a/modules/asyncConnect.js +++ b/modules/asyncConnect.js @@ -7,36 +7,37 @@ export const CLEAR = 'reduxAsyncConnect/CLEAR'; export const BEGIN_GLOBAL_LOAD = 'reduxAsyncConnect/BEGIN_GLOBAL_LOAD'; export const END_GLOBAL_LOAD = 'reduxAsyncConnect/END_GLOBAL_LOAD'; -export function reducer(state = {loaded: false}, action = {}) { +export function reducer(state = {loaded: false, loading: false}, action = {}) { const stateSlice = state[action.key]; switch (action.type) { case BEGIN_GLOBAL_LOAD: return { ...state, + loading: true, loaded: false }; case END_GLOBAL_LOAD: return { ...state, - + loading: false, loaded: true }; case LOAD: return { ...state, + loading: true, [action.key]: { ...stateSlice, - loading: true, loaded: false } }; case LOAD_SUCCESS: return { ...state, + loading: false, [action.key]: { ...stateSlice, - loading: false, loaded: true, data: action.data } @@ -44,9 +45,9 @@ export function reducer(state = {loaded: false}, action = {}) { case LOAD_FAIL: return { ...state, + loading: false, [action.key]: { ...stateSlice, - loading: false, loaded: false, error: action.error } @@ -54,9 +55,9 @@ export function reducer(state = {loaded: false}, action = {}) { case CLEAR: return { ...state, + loading: false, [action.key]: { - loaded: false, - loading: false + loaded: false } }; default: