You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
42 lines
1.2 KiB
const Immutable = require('immutable');
|
|
|
|
import * as BoardActions from '../../actions/board/board.actions';
|
|
import ValuesLogic from '../../logic/values.logic.js';
|
|
import { SETTINGS } from '../../App';
|
|
|
|
const initial = {
|
|
level: -1,
|
|
values: [],
|
|
title: 'Setting up...'
|
|
};
|
|
|
|
const count = SETTINGS.GRID_WIDTH * SETTINGS.GRID_HEIGHT;
|
|
|
|
const reducer = (state = initial, action) => {
|
|
if (action.type !== BoardActions.BOARD_ACTION) {
|
|
return state;
|
|
}
|
|
|
|
switch (action.action) {
|
|
case BoardActions.UPDATE:
|
|
return Immutable.fromJS(state).setIn(['values', action.index, 'value'], action.value).toJS();
|
|
|
|
case BoardActions.SHOW:
|
|
return Immutable.fromJS(state).setIn(['values', action.index, 'show'], true).toJS();
|
|
|
|
case BoardActions.HIDE:
|
|
return Immutable.fromJS(state).setIn(['values', action.index, 'show'], false).toJS();
|
|
|
|
case BoardActions.NEXT_LEVEL:
|
|
const lvl = state.level + 1;
|
|
return Immutable.Map(state)
|
|
.set('level', lvl)
|
|
.set('title', ValuesLogic.getDescription(lvl))
|
|
.set('values', ValuesLogic.generate(count, lvl))
|
|
.toObject();
|
|
}
|
|
|
|
return state;
|
|
};
|
|
|
|
export default reducer;
|
|
|