Skip to content

Instantly share code, notes, and snippets.

@halan
Created December 2, 2016 17:56
Show Gist options
  • Save halan/cd9e74323870496591332feb4cffc52d to your computer and use it in GitHub Desktop.
Save halan/cd9e74323870496591332feb4cffc52d to your computer and use it in GitHub Desktop.
import { createStore } from 'redux'
const eevee = { especie: 'Eevee', level: 1 };
const eeveelution = (state = eevee, action) => {
switch (action.type){
case 'WATER_STONE':
return { ...state, specie: 'Vaporeon' };
case 'THUNDER_STONE':
return { ...state, specie: 'Jolteon' };
case 'FIRE_STONE':
return { ...state, specie: 'Flareon' };
case 'LEVEL_UP':
return { ...state, level: state.level + 1};
default:
return state;
}
}
const store = createStore(eeveelution);
store.subscribe(() => console.log(store.getState()));
console.log(store);
store.dispatch({ type: 'WATER_STONE' });
store.dispatch({ type: 'LEVEL_UP' });
store.dispatch({ type: 'THUNDER_STONE' });
store.dispatch({ type: 'WATER_STONE' });
console.log(eevee);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment