Created
July 14, 2017 20:03
-
-
Save btg5679/097b591dd7dd7715f6e55a65fc363cc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore } from 'redux'; | |
// Store | |
const dataStore = createStore(r, { | |
beerlist: { | |
name: 'IPA', | |
abv: 7.4 | |
}, | |
beersOnTap: 1, | |
liveMusicHistory: { | |
bandName: 'Bahamas', | |
gigDate: '2017-01-01' | |
}, | |
... | |
}); | |
// Reducers | |
const beerlistReducer = (state, action){ | |
switch(action.type){ | |
case 'CHANGE_BEER_NAME': { | |
state = {...state, name: action.payload}// Create new state object | |
break; | |
} | |
case 'CHANGE_BEER_ABV': { | |
state = {...state, abv: action.payload}// Create new state object | |
break; | |
} | |
} | |
return state; | |
} | |
const beersOnTapReducer = (state, action){ | |
... | |
} | |
const liveMusicHistoryReducer = (state, action){ | |
... | |
} | |
const reducers = combineReducers({ | |
beerlist: beerlistReducer, | |
beersOnTap: beersOnTapReducer, | |
liveMusicHistory: liveMusicHistoryReducer | |
}) | |
// Actions | |
// Action dispatched to your Store | |
dataStore.dispatch({ type: 'CHANGE_BEER_NAME', payload: 'Stout' }); | |
dataStore.dispatch({ type: 'CHANGE_BEER_ABV', payload: 5.9 }); | |
// Called any time an action is dispatched | |
dataStore.subscribe(()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment