Last active
March 1, 2018 08:11
-
-
Save vvvyunnik/9302e99b723ba539b893e0bf981e86bc to your computer and use it in GitHub Desktop.
redux
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'; | |
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