Skip to content

Instantly share code, notes, and snippets.

@vkarpov15
Created September 10, 2018 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkarpov15/fb0ca30bc2c85c01f3626cbdfdd11b6d to your computer and use it in GitHub Desktop.
Save vkarpov15/fb0ca30bc2c85c01f3626cbdfdd11b6d to your computer and use it in GitHub Desktop.
// Sample Redux reducer
function reducer(state = { prices: {} }, action) {
console.log(`+${Date.now() - startTime}ms`, action);
switch (action.type) {
case 'FETCH_STOCK_PRICE_SUCCESS':
const prices = Object.assign({}, state.prices, { [action.symbol]: action.price });
state = Object.assign({}, state, { prices });
console.log('New state', state);
return state;
default:
return state;
}
}
store.dispatch({ type: 'FETCH_STOCK_PRICE', symbol: 'MDB' });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment