Slide 11
Slide 11 text
Changes:
{
game: {
board: {...},
started: false,
finished: false
}
}
Action-Creator
startGame(board)
State (in Store)
{
game: {
board: {
rows: [],
width: 5,
height: 5
},
started: false,
finished: false
}
}
dispatch(action)
gameReducer(state, action)
{
type: ‘START_GAME’,
board: {...}
}
App-Container
user clicks “start game”
function gameReducer(
state, action) {
switch (action.type) {
case START_GAME: {
const board = fromJS(
action.board);
return state
.set('board', board)
.set('score', 0)
.set('started', true)
.set('paused', false)
.set('finished', false);
}
default: {
return state;
}
}
getState() replace state
notify changes