React + Redux sample2

ただのRedux

by catfood

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.3.1/redux.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.js"></script>
<script src="https://babeljs.io/scripts/babel.js"></script>
<div id="root">
</div>

<script id="jsx-babelify" type="text/babel-jsx">
const {createStore} = Redux;

//reducer
function counter(state = 0, action) {
  switch (action.type) {
  case 'INCREMENT':
    return state + 1
  case 'DECREMENT':
    return state - 1
  default:
    return state
  }
}
//store
let store = createStore(counter)

// You can subscribe to the updates manuall
store.subscribe(() =>
  console.log(store.getState())
)

store.dispatch({ type: 'INCREMENT' })// 1
store.dispatch({ type: 'INCREMENT' })// 2
store.dispatch({ type: 'DECREMENT' })// 1


</script>

<script>
    var codeElem = document.getElementById('jsx-babelify');
    babel.run(codeElem.textContent, {
        stage: 0,
    })
</script>