Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Redux</title>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.0.4/redux.min.js"></script>
</head>
<body>
</body>
</html>
 
// 定義 reducer
const counter = (state = 0, action) =>{
  switch (action.type) {
    case 'INCREMENT':
      return state + 1;
    default:
      return state;
  }
}
const { createStore } = Redux;
// 產生 store
let store = createStore(counter);
// 透過 getState() 取得目前的 state
console.log('---prev state---');
console.log(store.getState());
// 透過 dispatch() 發送我們剛剛所定義的 action
store.dispatch({
  type: 'INCREMENT'
});
// 看執行後的 state
console.log('---next state---');
console.log(store.getState());
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
jigsawyepro
0viewers