Skip to content

Instantly share code, notes, and snippets.

@adilbenmoussa
Created May 26, 2017 08:36
Show Gist options
  • Save adilbenmoussa/c402e737c1baef7a3fba5a3e97f57da6 to your computer and use it in GitHub Desktop.
Save adilbenmoussa/c402e737c1baef7a3fba5a3e97f57da6 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/bobitif
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://unpkg.com/expect/umd/expect.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.6.0/redux.js"></script>
<script src="https://fb.me/react-15.1.0.js"></script>
<script src="https://fb.me/react-dom-15.1.0.js"></script>
<title>JS Bin</title>
</head>
<body>
<div id="root"></div>
<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;
case 'DECREMENT':
return state - 1;
default:
return state;
}
};
var _Redux = Redux;
var createStore = _Redux.createStore;
var Counter = function Counter(_ref) {
var value = _ref.value;
var onIncrement = _ref.onIncrement;
var onDecrement = _ref.onDecrement;
return React.createElement(
'div',
null,
React.createElement(
'h1',
null,
' ',
value,
' '
),
React.createElement(
'button',
{ onClick: onIncrement },
'+'
),
React.createElement(
'button',
{ onClick: onDecrement },
'-'
)
);
};
var store = createStore(counter);
var render = function render() {
ReactDOM.render(React.createElement(Counter, {
value: store.getState(),
onIncrement: function () {
return store.dispatch({ type: 'INCREMENT' });
},
onDecrement: function () {
return store.dispatch({ type: 'DECREMENT' });
} }), document.getElementById('root'));
};
store.subscribe(render);
render();
</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 Counter = ({
value,
onIncrement,
onDecrement
}) => (
<div>
<h1> {value} </h1>
<button onClick={onIncrement}>+</button>
<button onClick={onDecrement}>-</button>
</div>
);
const store = createStore(counter);
const render = () => {
ReactDOM.render (
<Counter
value={store.getState()}
onIncrement = {()=>
store.dispatch({type: 'INCREMENT'})
}
onDecrement = {()=>
store.dispatch({type: 'DECREMENT'})
}/>,
document.getElementById('root')
);
};
store.subscribe(render);
render();
</script></body>
</html>
'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 Counter = function Counter(_ref) {
var value = _ref.value;
var onIncrement = _ref.onIncrement;
var onDecrement = _ref.onDecrement;
return React.createElement(
'div',
null,
React.createElement(
'h1',
null,
' ',
value,
' '
),
React.createElement(
'button',
{ onClick: onIncrement },
'+'
),
React.createElement(
'button',
{ onClick: onDecrement },
'-'
)
);
};
var store = createStore(counter);
var render = function render() {
ReactDOM.render(React.createElement(Counter, {
value: store.getState(),
onIncrement: function () {
return store.dispatch({ type: 'INCREMENT' });
},
onDecrement: function () {
return store.dispatch({ type: 'DECREMENT' });
} }), document.getElementById('root'));
};
store.subscribe(render);
render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment