際際滷

際際滷Share a Scribd company logo
Redux and Redux saga
,help@birdsfree.com
Redux ?
′朱 ろ危碁ゼ 覲蟆渚伎朱 .
襴る 蟆
企蟆 蟲焔  Action, Reducer , Store
-Action: 企  蠍   螳豌企一危 e.g: { type: ′企 , 覲: ..,
覲.. }轟朱  type 企朱 螻褐 ′ 螻 企 誤 る 蟆. (願
朱 ′ 覲企 螻褐 企 ′ れ伎讌 語)
豌 覯讌, Action
-Action: 企  蠍   螳豌企一危 e.g: { type: ′企 , 覲: ..,
覲.. }轟朱  type 企朱 螻褐 ′ 螻 企 誤 る 蟆. (願
朱 ′ 覲企 螻褐 企 ′ れ伎讌 語)
蠍一 譴 蟆 螳 貊 覲伎企 Type safe襯 伎  貊 蟯
 type . 蠏語 ′  螻 覈 蠍 伎 伎 type企朱
key,value  key 螳
 覯讌, Reducer
襴 蠏語 伎  state 襯 襦 state 襦 覲蟆 伎朱 .
襯 れ伎 伎 state 螳 {myName : im crazy } 螻 願  蟆  ろ
碁ゼ 覲蟆渚螻 覃{myName:im not crazy yourName:you are crazy} 手
覦蠑碁  reducer  .
貊 語 覲危 企蟆 伎. (願係危語 redux 启 谿瑚).
export const request = (state: Object) => state.merge({ fetching: true })
伎 state 螳 蟆 れ伎る fetching 企朱 襦 螳 伎 ろ危
(state:Object)  ロ伎 蟆譴.
 覯讌, Reducer
襴  襷 蟆豌 蟆 ろ危 覲蟆曙 誤 れ,
export const reducer = createReducer(INITIAL_STATE, {
[Types.LOGIN_REQUEST]: request,
[Types.LOGIN_SUCCESS]: success,
[Types.LOGIN_FAILURE]: failure,
[Types.LOGOUT]: logout
})
企蟆 action 螻 襷れ広 譴朱. Types.LOGIN_REQUEST  action  殊企襴
   碁    { type: login_request_unique} 螳 螳
 れ伎蟆る 蟆 豢 豸″  . 蟆   伎 轟壱 
豌 key,value 螳朱 企伎 覦一企 ′ 螻 語蠍 覿ク蠍 覓語.
蠍一 蟾, ActionCreater  伎 覲伎
(redux/LoginRedux.js  谿瑚)  ′  貊.
export const reducer = createReducer(INITIAL_STATE, {
[Types.LOGIN_REQUEST]: request,
[Types.LOGIN_SUCCESS]: success,
[Types.LOGIN_FAILURE]: failure,
[Types.LOGOUT]: logout
})
Types.LOGIN_REQUEST 朱 ′襯 襷れ 譯朱 library 螳 
.(/Redux/LoginRedux.js    谿瑚)
import { createReducer, createActions } from 'reduxsauce'
覦襦  貊 createActions .
蠍一 蟾, ActionCreater  伎 覲伎
  貊襯 覿覃
const { Types, Creators } = createActions({
loginRequest: ['username', 'password'],
loginSuccess: ['username'],
loginFailure: ['error'],
logout: null
})
export const LoginTypes = Types
export default Creators
createAction 伎  蟆郁骸覓殊 Types.LOGIN_REQUEST 朱 Action 螳
襷れ伎, createActions  loginRequest:[username,password]  
Types.LOGIN_REQUEST ={ type: loginRequest username: password:}
企 螳. り 蟆 ′ 襷れ広伎 襷れ 譴.
襷讌襷 store
store  覲蟇 . reducer  action  誤 れ 覲危
企蟆 襷れ広伎朱
export const reducer = createReducer(INITIAL_STATE, {
[Types.LOGIN_REQUEST]: request,
[Types.LOGIN_SUCCESS]: success,
[Types.LOGIN_FAILURE]: failure,
[Types.LOGOUT]: logout
})
襷れ企 襴 ′ ′:襴 襦 豌 襷れ広. 蠏碁Μ螻 createReducer
襦 襴襯 襷り ,  襴 INITIAL_STATE襯 ′ 磯殊 襴襯 語伎
覲蟆渚伎朱 蟆.
襷讌襷 store
store  螳. reducer  action  誤 れ 覲危
企蟆 襷れ広伎朱 (redux/LoginRedux.js 谿瑚)
export const reducer = createReducer(INITIAL_STATE, {
[Types.LOGIN_REQUEST]: request,
[Types.LOGIN_SUCCESS]: success,
[Types.LOGIN_FAILURE]: failure,
[Types.LOGOUT]: logout
})
襷れ企 襴 ′ ′:襴 襦 豌 襷れ広. 蠏碁Μ螻 createReducer
襦 襴襯 襷り ,  襴 INITIAL_STATE襯 ′ 磯殊 襴襯 語伎
覲蟆渚伎朱 蟆.
襷讌襷 store
襷れ伎 reducerれ 豌 襭碁Μ襦 豺螻, 蠏 れ  襴襯 store 
k 蟆.
export default () => {
/* ------------- Assemble The Reducers ------------- */
const rootReducer = combineReducers({
temperature: require('./TemperatureRedux').reducer,
login: require('./LoginRedux').reducer,
search: require('./SearchRedux').reducer,
})
return configureStore(rootReducer, rootSaga)
}
襷讌襷 store
蠏  磯Μ れ 襴 貉朱語 store り ′ 讌覃(dispatch襯 
伎 讌.)
蠏 store 磯Μ螳 襷 rootReducer 螳 蠏 ′ 螳讌螻, 襷れ広 
Reducer襯 語  蟆.!!
Redux End!!
蠏 れ Redux saga 襯 る.

More Related Content

Redux and redux saga

  • 1. Redux and Redux saga ,help@birdsfree.com
  • 2. Redux ? ′朱 ろ危碁ゼ 覲蟆渚伎朱 . 襴る 蟆 企蟆 蟲焔 Action, Reducer , Store -Action: 企 蠍 螳豌企一危 e.g: { type: ′企 , 覲: .., 覲.. }轟朱 type 企朱 螻褐 ′ 螻 企 誤 る 蟆. (願 朱 ′ 覲企 螻褐 企 ′ れ伎讌 語)
  • 3. 豌 覯讌, Action -Action: 企 蠍 螳豌企一危 e.g: { type: ′企 , 覲: .., 覲.. }轟朱 type 企朱 螻褐 ′ 螻 企 誤 る 蟆. (願 朱 ′ 覲企 螻褐 企 ′ れ伎讌 語) 蠍一 譴 蟆 螳 貊 覲伎企 Type safe襯 伎 貊 蟯 type . 蠏語 ′ 螻 覈 蠍 伎 伎 type企朱 key,value key 螳
  • 4. 覯讌, Reducer 襴 蠏語 伎 state 襯 襦 state 襦 覲蟆 伎朱 . 襯 れ伎 伎 state 螳 {myName : im crazy } 螻 願 蟆 ろ 碁ゼ 覲蟆渚螻 覃{myName:im not crazy yourName:you are crazy} 手 覦蠑碁 reducer . 貊 語 覲危 企蟆 伎. (願係危語 redux 启 谿瑚). export const request = (state: Object) => state.merge({ fetching: true }) 伎 state 螳 蟆 れ伎る fetching 企朱 襦 螳 伎 ろ危 (state:Object) ロ伎 蟆譴.
  • 5. 覯讌, Reducer 襴 襷 蟆豌 蟆 ろ危 覲蟆曙 誤 れ, export const reducer = createReducer(INITIAL_STATE, { [Types.LOGIN_REQUEST]: request, [Types.LOGIN_SUCCESS]: success, [Types.LOGIN_FAILURE]: failure, [Types.LOGOUT]: logout }) 企蟆 action 螻 襷れ広 譴朱. Types.LOGIN_REQUEST action 殊企襴 碁 { type: login_request_unique} 螳 螳 れ伎蟆る 蟆 豢 豸″ . 蟆 伎 轟壱 豌 key,value 螳朱 企伎 覦一企 ′ 螻 語蠍 覿ク蠍 覓語.
  • 6. 蠍一 蟾, ActionCreater 伎 覲伎 (redux/LoginRedux.js 谿瑚) ′ 貊. export const reducer = createReducer(INITIAL_STATE, { [Types.LOGIN_REQUEST]: request, [Types.LOGIN_SUCCESS]: success, [Types.LOGIN_FAILURE]: failure, [Types.LOGOUT]: logout }) Types.LOGIN_REQUEST 朱 ′襯 襷れ 譯朱 library 螳 .(/Redux/LoginRedux.js 谿瑚) import { createReducer, createActions } from 'reduxsauce' 覦襦 貊 createActions .
  • 7. 蠍一 蟾, ActionCreater 伎 覲伎 貊襯 覿覃 const { Types, Creators } = createActions({ loginRequest: ['username', 'password'], loginSuccess: ['username'], loginFailure: ['error'], logout: null }) export const LoginTypes = Types export default Creators createAction 伎 蟆郁骸覓殊 Types.LOGIN_REQUEST 朱 Action 螳 襷れ伎, createActions loginRequest:[username,password] Types.LOGIN_REQUEST ={ type: loginRequest username: password:} 企 螳. り 蟆 ′ 襷れ広伎 襷れ 譴.
  • 8. 襷讌襷 store store 覲蟇 . reducer action 誤 れ 覲危 企蟆 襷れ広伎朱 export const reducer = createReducer(INITIAL_STATE, { [Types.LOGIN_REQUEST]: request, [Types.LOGIN_SUCCESS]: success, [Types.LOGIN_FAILURE]: failure, [Types.LOGOUT]: logout }) 襷れ企 襴 ′ ′:襴 襦 豌 襷れ広. 蠏碁Μ螻 createReducer 襦 襴襯 襷り , 襴 INITIAL_STATE襯 ′ 磯殊 襴襯 語伎 覲蟆渚伎朱 蟆.
  • 9. 襷讌襷 store store 螳. reducer action 誤 れ 覲危 企蟆 襷れ広伎朱 (redux/LoginRedux.js 谿瑚) export const reducer = createReducer(INITIAL_STATE, { [Types.LOGIN_REQUEST]: request, [Types.LOGIN_SUCCESS]: success, [Types.LOGIN_FAILURE]: failure, [Types.LOGOUT]: logout }) 襷れ企 襴 ′ ′:襴 襦 豌 襷れ広. 蠏碁Μ螻 createReducer 襦 襴襯 襷り , 襴 INITIAL_STATE襯 ′ 磯殊 襴襯 語伎 覲蟆渚伎朱 蟆.
  • 10. 襷讌襷 store 襷れ伎 reducerれ 豌 襭碁Μ襦 豺螻, 蠏 れ 襴襯 store k 蟆. export default () => { /* ------------- Assemble The Reducers ------------- */ const rootReducer = combineReducers({ temperature: require('./TemperatureRedux').reducer, login: require('./LoginRedux').reducer, search: require('./SearchRedux').reducer, }) return configureStore(rootReducer, rootSaga) }
  • 11. 襷讌襷 store 蠏 磯Μ れ 襴 貉朱語 store り ′ 讌覃(dispatch襯 伎 讌.) 蠏 store 磯Μ螳 襷 rootReducer 螳 蠏 ′ 螳讌螻, 襷れ広 Reducer襯 語 蟆.!! Redux End!! 蠏 れ Redux saga 襯 る.