Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add loading to root store #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions modules/asyncConnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,57 @@ 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
}
};
case LOAD_FAIL:
return {
...state,
loading: false,
[action.key]: {
...stateSlice,
loading: false,
loaded: false,
error: action.error
}
};
case CLEAR:
return {
...state,
loading: false,
[action.key]: {
loaded: false,
loading: false
loaded: false
}
};
default:
Expand Down