Last active
May 18, 2017 18:35
-
-
Save malectro/601b0cdb88045fb6f1e2049d22a2ea22 to your computer and use it in GitHub Desktop.
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 usersReducer = (state = {users: {}, fetching: {}, cache: {}}, {type, payload}) => { | |
switch (type) { | |
case START_FETCHING: | |
return { | |
...state, | |
fetching: { | |
...state.fetching, | |
[payload.userId]: payload.promise, | |
}, | |
}; | |
case STOP_FETCHING: | |
return { | |
...state, | |
fetching: { | |
...state.fetching, | |
[payload.userId]: null, | |
}, | |
}; | |
case RECEIVE_USER: | |
return { | |
...state, | |
cache: { | |
...state.fetching, | |
[payload.user.id]: { | |
expireTime: Date.now() + 60000, | |
}, | |
}, | |
users: { | |
...state.users, | |
[payload.user.id]: payload.user, | |
}, | |
}; | |
} | |
return state; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment