lbry-desktop/ui/js/reducers/user.js

35 lines
800 B
JavaScript
Raw Normal View History

2017-06-01 18:20:12 +02:00
import * as types from 'constants/action_types'
const reducers = {}
const defaultState = {
authenticationIsPending: false,
user: undefined
}
reducers[types.AUTHENTICATION_STARTED] = function(state, action) {
return Object.assign({}, state, {
authenticationIsPending: true
})
}
reducers[types.AUTHENTICATION_SUCCESS] = function(state, action) {
return Object.assign({}, state, {
authenticationIsPending: false,
user: action.data.user,
})
}
reducers[types.AUTHENTICATION_FAILURE] = function(state, action) {
return Object.assign({}, state, {
authenticationIsPending: false,
user: null,
})
}
export default function reducer(state = defaultState, action) {
const handler = reducers[action.type];
if (handler) return handler(state, action);
return state;
}