(I’ll explain more later.)
If all your reducers are going to be using scour, you can set your state
as a scour-wrapped object.
We’re going to use a scour-wrapped object as the initialState
for createStore()
.
import { createStore } from 'redux'
function reducer (state, action) {
/* `state` is a scour-wrapped object. */
switch (action.type) {
case 'LOAD_TRACKS':
return state.set('tracks', action.data)
case 'PLAY':
return state.set('audio.state', 'playing')
case 'STOP':
return state.set('audio.state', 'stopped')
case 'SELECT_TRACK':
var track = state.go('tracks', action.trackId)
return state.set('audio.current_track', track)
}
return state
}
store = createStore(reducer, scour({}))
Here’s an example.
store.dispatch({
type: 'LOAD_TRACKS',
data: {
1: { title: 'Levels', artist: 'Avicii' },
2: { title: 'Bonfire', artist: 'Knife Party' },
3: { title: 'Hello', artist: 'Adele' }
}
})
store.dispatch({ type: 'SELECT_TRACK', 3 })
store.dispatch({ type: 'PLAY' })
Hmm… I’ll explain later.