Last active
March 7, 2016 23:29
-
-
Save chuck0523/80dc6ea1c4a395386b00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore } from 'redux' | |
// reducer。actionを受けてstateを変更するメソッド。 | |
// stateの初期値を0としている。 | |
function counter(state = 0, action) { | |
switch (action.type) { | |
case 'INCREMENT': | |
return state + 1 | |
case 'DECREMENT': | |
return state - 1 | |
default: | |
return state | |
} | |
} | |
let store = createStore(counter) | |
// subscribeを使って、リスナーを登録。 | |
store.subscribe(() => | |
console.log(store.getState()) | |
) | |
// actionをdispatchしている。 | |
// action = アプリケーションの情報をstoreに送るためのオブジェクト。 | |
// type: 何を行うかを識別するプロパティ。 | |
store.dispatch({ type: 'INCREMENT' }) | |
// 1 | |
store.dispatch({ type: 'INCREMENT' }) | |
// 2 | |
store.dispatch({ type: 'DECREMENT' }) | |
// 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment