Soccer Game App with Redux-Leaves
// setup
const { createStore } = require('redux')
const { reduxLeaves, bundle } = require('redux-leaves')
// declare initial state
const initialState = {
crowdExcitement: 0,
scoreboard: {
home: 0,
away: 0
}
}
// pass to reduxLeaves and get back a reducer and action creators
const [reducer, actions] = reduxLeaves(initialState)
const store = createStore(reducer)
store.getState()
// at storeState.scoreboard.away, create an action to increment
store.dispatch(actions.scoreboard.away.create.increment())
store.getState()
// in a single action, do both:
// a) at storeState.scoreboard.home, increment state
// b) at storeState.crowdExcitement, increment state by 5
const bundledAction = bundle([
actions.scoreboard.home.create.increment(),
actions.crowdExcitement.create.increment(5)
])
store.dispatch(bundledAction)
store.getState()
no comments