Skip to content

Instantly share code, notes, and snippets.

@vvvyunnik
Last active March 1, 2018 08:11
Show Gist options
  • Save vvvyunnik/9302e99b723ba539b893e0bf981e86bc to your computer and use it in GitHub Desktop.
Save vvvyunnik/9302e99b723ba539b893e0bf981e86bc to your computer and use it in GitHub Desktop.
redux
import { createStore } from 'redux';
const geometricProgressionRatio = 2;
const arithmeticProgressionRatio = 2;
const geometricProgression = {
type: "GEOMETRIC_PROGRESSION",
by: geometricProgressionRatio
};
const arithmeticProgression = {
type: "ARITHMETIC_PROGRESSION",
by: arithmeticProgressionRatio
};
function counter(state = 1, action) {
switch (action.type) {
case 'GEOMETRIC_PROGRESSION':
return state * action.by;
case 'ARITHMETIC_PROGRESSION':
return state + action.by;
default:
return state;
}
}
const store = createStore(counter);
const unsubscribe = store.subscribe(() => {
console.log(store.getState())
});
for (let i = 0; i < 10; i++) {
store.dispatch(geometricProgression);
}
for (let i = 0; i < 10; i++) {
store.dispatch(arithmeticProgression);
}
unsubscribe();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment