Last active
May 2, 2018 08:24
-
-
Save miladvafaeifard/441ee78492b9692df67539eb721b3e33 to your computer and use it in GitHub Desktop.
Redux Sample JS Bin, source http://jsbin.com/qavifum
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
const counter = (state = 0, action) => { | |
switch(action.type){ | |
case 'INCREMENT': | |
return state + 1; | |
case 'DECREMENT': | |
return state - 1; | |
default: | |
return state; | |
} | |
} | |
const { createStore } = Redux; | |
// describe("Redux Texts", function(){ | |
// it("Tests passed", function(){ | |
// expect(counter(0, {type: 'INCREMENT'})).toEqual(1); | |
// expect(counter(3, {type: 'INCREMENT'})).toEqual(4); | |
// expect(counter(4, {type: 'DECREMENT'})).toEqual(3); | |
// expect(counter(1, {type: 'DECREMENT'})).toEqual(0); | |
// expect(counter(undefined, {})).toEqual(0); | |
// }); | |
// }); | |
const store = createStore(counter); | |
const render = () => { | |
document.body.innerText = store.getState(); | |
}; | |
store.subscribe(render); | |
render(); | |
document.addEventListener('click', _ => { | |
store.dispatch({type: 'INCREMENT'}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment