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-18 06:20:21 +00:00
|
|
|
import { errorReducer } from './err/stateReducer.err';
|
2020-01-18 00:32:40 +00:00
|
|
|
import { indexReducer } from './index/stateReducer.index';
|
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 22:27:31 +00:00
|
|
|
|
2020-01-16 08:22:27 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case 'INIT': return initState();
|
2020-01-18 06:20:21 +00:00
|
|
|
|
|
|
|
case 'AUTH':
|
|
|
|
return authReducer(errorStrippedState, action);
|
2020-01-17 00:59:11 +00:00
|
|
|
|
2020-01-18 00:32:40 +00:00
|
|
|
case 'INDEX':
|
|
|
|
return indexReducer(errorStrippedState, action);
|
|
|
|
|
2020-01-18 06:20:21 +00:00
|
|
|
case 'ERR':
|
|
|
|
return errorReducer(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
|
|
|
}
|