Created
May 24, 2017 23:47
-
-
Save thechutrain/1b63a97a98d249cab9418aa1477917c7 to your computer and use it in GitHub Desktop.
JS Bin Reducer-example // source https://jsbin.com/mirenat
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="Reducer-example"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script src="https://unpkg.com/expect/umd/expect.min.js"></script> | |
<script src="https://fb.me/react-0.14.0.min.js"></script> | |
<script src="https://fb.me/react-dom-0.14.0.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.0.4/redux.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-redux/4.0.0/react-redux.min.js"></script> | |
<script id="jsbin-javascript"> | |
'use strict'; | |
var counter = function counter(state, action) { | |
if (state === undefined) state = 0; | |
switch (action.type) { | |
case 'INCREMENT': | |
return state + 1; | |
break; | |
case 'DECREMENT': | |
return state - 1; | |
break; | |
default: | |
return state; | |
break; | |
} | |
}; | |
var _Redux = Redux; | |
var createStore = _Redux.createStore; | |
var store = createStore(counter); // create store with a reducer of counter | |
// console.log(store.getState()); | |
var render = function render() { | |
document.body.innerText = store.getState(); | |
}; | |
store.subscribe(render); | |
render(); | |
document.addEventListener('click', function () { | |
store.dispatch({ type: 'INCREMENT' }); | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const counter = (state = 0, action) => { | |
switch(action.type) { | |
case 'INCREMENT': | |
return state + 1; | |
break; | |
case 'DECREMENT': | |
return state - 1; | |
break; | |
default: | |
return state; | |
break; | |
} | |
} | |
const { createStore } = Redux; | |
const store = createStore(counter); // create store with a reducer of counter | |
// console.log(store.getState()); | |
const render = () => { | |
document.body.innerText = store.getState(); | |
} | |
store.subscribe(render) | |
render() | |
document.addEventListener('click', () => { | |
store.dispatch({ type: 'INCREMENT'}) | |
})</script></body> | |
</html> |
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; | |
break; | |
case 'DECREMENT': | |
return state - 1; | |
break; | |
default: | |
return state; | |
break; | |
} | |
}; | |
var _Redux = Redux; | |
var createStore = _Redux.createStore; | |
var store = createStore(counter); // create store with a reducer of counter | |
// console.log(store.getState()); | |
var render = function render() { | |
document.body.innerText = store.getState(); | |
}; | |
store.subscribe(render); | |
render(); | |
document.addEventListener('click', function () { | |
store.dispatch({ type: 'INCREMENT' }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment