2020-01-16 08:22:27 +00:00
|
|
|
// @flow
|
|
|
|
import { initState } from './init/stateReducer.init';
|
2020-01-17 00:59:11 +00:00
|
|
|
import { authReducer } from './auth/stateReducer.auth';
|
2020-01-16 08:22:27 +00:00
|
|
|
|
|
|
|
export type state = {
|
2020-01-17 00:59:11 +00:00
|
|
|
user: {},
|
|
|
|
errors: {}
|
2020-01-16 08:22:27 +00:00
|
|
|
}
|
|
|
|
|
2020-01-17 00:59:11 +00:00
|
|
|
export type action = {
|
|
|
|
type: string,
|
|
|
|
message: ?string,
|
|
|
|
body: {}
|
2020-01-16 08:22:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const stateReducer = (state: state, action: action): state => {
|
2020-01-17 00:59:11 +00:00
|
|
|
const errorStrippedState = stripErrors({...state});
|
2020-01-17 20:21:43 +00:00
|
|
|
console.log(action)
|
2020-01-16 08:22:27 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case 'INIT': return initState();
|
2020-01-17 00:59:11 +00:00
|
|
|
|
2020-01-17 20:21:43 +00:00
|
|
|
case 'AUTH':
|
|
|
|
return authReducer(errorStrippedState, action);
|
2020-01-16 08:22:27 +00:00
|
|
|
|
|
|
|
default: return state;
|
|
|
|
}
|
2020-01-17 00:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function stripErrors(state: state): state {
|
|
|
|
return {...state, errors: {}}
|
2020-01-16 08:22:27 +00:00
|
|
|
}
|