parent
a660ff6b78
commit
4c671ec007
17 changed files with 214 additions and 235 deletions
@ -0,0 +1,35 @@ |
|||||||
|
export const BOARD_ACTION = 'BOARD_ACTION'; |
||||||
|
export const GENERATE = 'GENERATE'; |
||||||
|
export const UPDATE = 'UPDATE'; |
||||||
|
export const HIDE = 'HIDE'; |
||||||
|
export const SHOW = 'SHOW'; |
||||||
|
export const NEXT_LEVEL = 'NEXT_LEVEL'; |
||||||
|
|
||||||
|
export const generateValues = () => ({ |
||||||
|
type: BOARD_ACTION, |
||||||
|
action: GENERATE |
||||||
|
}); |
||||||
|
|
||||||
|
export const updateValue = (index, value) => ({ |
||||||
|
type: BOARD_ACTION, |
||||||
|
action: UPDATE, |
||||||
|
index: index, |
||||||
|
value: value |
||||||
|
}); |
||||||
|
|
||||||
|
export const showValue = (index) => ({ |
||||||
|
type: BOARD_ACTION, |
||||||
|
action: SHOW, |
||||||
|
index: index |
||||||
|
}); |
||||||
|
|
||||||
|
export const hideValue = (index) => ({ |
||||||
|
type: BOARD_ACTION, |
||||||
|
action: HIDE, |
||||||
|
index: index |
||||||
|
}); |
||||||
|
|
||||||
|
export const nextLevel = () => ({ |
||||||
|
type: BOARD_ACTION, |
||||||
|
action: NEXT_LEVEL |
||||||
|
}); |
@ -1,18 +0,0 @@ |
|||||||
// Grid component actions and action creators.
|
|
||||||
export const GRID_ACTION = 'GRID_ACTION'; |
|
||||||
export const GENERATE = 'GENERATE'; |
|
||||||
export const UPDATE = 'UPDATE'; |
|
||||||
|
|
||||||
export const generateValues = (count, level) => ({ |
|
||||||
type: GRID_ACTION, |
|
||||||
action: GENERATE, |
|
||||||
count: count, |
|
||||||
level: level |
|
||||||
}); |
|
||||||
|
|
||||||
export const updateValues = (index, value) => ({ |
|
||||||
type: GRID_ACTION, |
|
||||||
action: UPDATE, |
|
||||||
index: index, |
|
||||||
value: value |
|
||||||
}); |
|
@ -0,0 +1,42 @@ |
|||||||
|
const Immutable = require('immutable'); |
||||||
|
|
||||||
|
import * as BoardActions from '../../actions/board/board.actions'; |
||||||
|
import Values from '../Values'; |
||||||
|
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', Values.getDescription(lvl)) |
||||||
|
.set('values', Values.generate(count, lvl)) |
||||||
|
.toObject(); |
||||||
|
} |
||||||
|
|
||||||
|
return state; |
||||||
|
}; |
||||||
|
|
||||||
|
export default reducer; |
@ -1,24 +0,0 @@ |
|||||||
const Immutable = require('immutable'); |
|
||||||
|
|
||||||
import * as GridActions from '../../actions/board/grid.actions'; |
|
||||||
import Values from '../Values'; |
|
||||||
|
|
||||||
const initial = []; |
|
||||||
|
|
||||||
const reducer = (state = initial, action) => { |
|
||||||
if (action.type !== GridActions.GRID_ACTION) { |
|
||||||
return state; |
|
||||||
} |
|
||||||
|
|
||||||
switch (action.action) { |
|
||||||
case GridActions.GENERATE: |
|
||||||
return Values.generate(action.count, action.level); |
|
||||||
|
|
||||||
case GridActions.UPDATE: |
|
||||||
return Immutable.List(state).set(action.index, action.value).toArray(); |
|
||||||
} |
|
||||||
|
|
||||||
return state; |
|
||||||
}; |
|
||||||
|
|
||||||
export default reducer; |
|
Loading…
Reference in new issue