Skip to content

Instantly share code, notes, and snippets.

Created September 20, 2016 05:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3244d9b8a48444c7eee4cf6a8c5acd83 to your computer and use it in GitHub Desktop.
Save anonymous/3244d9b8a48444c7eee4cf6a8c5acd83 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/lekutu
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://unpkg.com/redux@3.6.0/dist/redux.min.js"></script>
<script id="jsbin-javascript">
//const createStore = require('redux').createStore
'use strict';
var createStore = Redux.createStore;
function todos(state, action) {
if (state === undefined) state = [];
switch (action.type) {
case 'ADD_TODO':
return state.concat([action.text]);
default:
return state;
}
}
var store = createStore(todos, ['Use Redux']);
store.dispatch({
type: 'ADD_TODO',
text: 'Read the docs'
});
store.dispatch({
type: 'ADD_TODO',
text: 'FUCK'
});
console.log(store.getState());
// [ 'Use Redux', 'Read the docs' ]
</script>
<script id="jsbin-source-javascript" type="text/javascript">//const createStore = require('redux').createStore
var createStore = Redux.createStore
function todos(state = [], action) {
switch (action.type) {
case 'ADD_TODO':
return state.concat([ action.text ])
default:
return state
}
}
let store = createStore(todos, [ 'Use Redux' ], )
store.dispatch({
type: 'ADD_TODO',
text: 'Read the docs'
})
store.dispatch({
type: 'ADD_TODO',
text: 'FUCK'
})
console.log(store.getState())
// [ 'Use Redux', 'Read the docs' ]</script></body>
</html>
//const createStore = require('redux').createStore
'use strict';
var createStore = Redux.createStore;
function todos(state, action) {
if (state === undefined) state = [];
switch (action.type) {
case 'ADD_TODO':
return state.concat([action.text]);
default:
return state;
}
}
var store = createStore(todos, ['Use Redux']);
store.dispatch({
type: 'ADD_TODO',
text: 'Read the docs'
});
store.dispatch({
type: 'ADD_TODO',
text: 'FUCK'
});
console.log(store.getState());
// [ 'Use Redux', 'Read the docs' ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment