node-go/packages/server/play-node-go/src/reducers/stateReducer.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

// @flow
import { initState } from './init/stateReducer.init';
import { authReducer } from './auth/stateReducer.auth';
import { errorReducer } from './err/stateReducer.err';
2020-01-18 00:32:40 +00:00
import { indexReducer } from './index/stateReducer.index';
2020-01-19 00:17:23 +00:00
import { roomsReducer } from './rooms/stateReducer.rooms';
2020-01-22 23:41:08 +00:00
import { messagesReducer } from './messages/stateReducer.messages';
import { gamesReducer } from './games/stateReducer.games';
export type state = {
user: {},
2020-01-22 23:41:08 +00:00
errors: {},
messages: []
}
export type action = {
type: string,
message: ?string,
2020-01-22 23:41:08 +00:00
body: {} | Array<{}>,
}
export const stateReducer = (state: state, action: action): state => {
const errorStrippedState = stripErrors({...state});
switch (action.type) {
case 'INIT': return initState();
case 'AUTH':
return authReducer(errorStrippedState, action);
case 'GAMES':
return gamesReducer(errorStrippedState, action);
2020-01-18 00:32:40 +00:00
case 'INDEX':
return indexReducer(errorStrippedState, action);
2020-01-22 23:41:08 +00:00
case 'MESSAGES':
return messagesReducer(errorStrippedState, action);
2020-01-19 00:17:23 +00:00
case 'ROOMS':
return roomsReducer(errorStrippedState, action);
case 'ERR':
return errorReducer(errorStrippedState, action);
default: return state;
}
}
function stripErrors(state: state): state {
return {...state, errors: {}}
}