Last active
September 21, 2017 14:19
-
-
Save th3mon/473ed172d740f273e5c5d08b7cfc6e2b to your computer and use it in GitHub Desktop.
Redux, simple app
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'; | |
console.clear(); | |
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()) | |
var render = function render() { | |
return document.body.innerText = store.getState(); | |
}; | |
store.subscribe(render); | |
render(); | |
document.addEventListener('click', function () { | |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.0.4/redux.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/expect/1.20.2/expect.min.js"></script> | |
<script id="jsbin-javascript"> | |
'use strict'; | |
console.clear(); | |
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()) | |
var render = function render() { | |
return 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"> | |
'use strict' | |
console.clear() | |
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) | |
console.log(store.getState()) | |
// store.dispatch({ type: 'INCREMENT' }) | |
// 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment