Last active
June 8, 2017 05:19
-
-
Save TapaniAla/fd15032773ac4ad98cc942b1b355ca35 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/cequnu
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; | |
const store = createStore(counter); | |
const render = () => { | |
document.body.innerText = store.getState(); | |
} | |
// Needed to show initial state 0 | |
store.subscribe(render); | |
// Needed to show initial state 0 | |
render(); | |
document.addEventListener('click', () => { | |
store.dispatch({type:'INCREMENT'}); | |
}); | |
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
'use strict'; | |
var counter = function counter(state, action) { | |
if (state === undefined) state = 0; | |
switch (action.type) { | |
case 'INCREMENT': | |
return state + 1; | |
case 'DECREMENT': | |
return state - 1; | |
default: | |
return state; | |
} | |
}; | |
var _Redux = Redux; | |
var createStore = _Redux.createStore; | |
var store = createStore(counter); | |
console.log(store.getState()); | |
store.dispatch({ type: 'INCREMENT' }); | |
console.log(store.getState()); |
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; | |
const store = createStore(counter); | |
store.subscribe(() => { | |
document.body.innerText = store.getState(); | |
}); | |
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