Skip to content

Instantly share code, notes, and snippets.

@musale
Created April 6, 2017 06:46
Show Gist options
  • Save musale/fc07fe17351b5969d732a311a089a261 to your computer and use it in GitHub Desktop.
Save musale/fc07fe17351b5969d732a311a089a261 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/rodoyaj
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.6.0/redux.js"></script>
</head>
<body>
<script id="jsbin-javascript">
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();
}
store.subscribe(render);
render();
document.addEventListener('click', ()=>{
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
case('DECREMENT'):
return state - 1
default:
return state
}
}
const { createStore } = Redux;
const store = createStore(counter);
const render = ()=>{
document.body.innerText = store.getState();
}
store.subscribe(render);
render();
document.addEventListener('click', ()=>{
store.dispatch({type: 'INCREMENT'})
})
</script></body>
</html>
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();
}
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