Last active
August 29, 2015 14:26
-
-
Save Jazznight/77b762d73c16c854cf26 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 1. 將 ajax 的行為都定義在 actions 裡,例如 ProductionActions.js | |
| export function getAllProduction () { | |
| return (dispatch) => { | |
| $.ajax('xxx/products', { | |
| success: (data) => { | |
| disptach({ | |
| type: GET_PRODUCTS | |
| data" data | |
| }); | |
| } | |
| } | |
| } | |
| } | |
| 也就是外部觸發 actions 時才去做 ajax | |
| 流程:action -> ajax --> ajax success callback -> dispatch | |
| 2. 將 ajax 的行為都定義在其他地方, actions 只作簡單定義 ,例如 ProductionActions.js | |
| export function getAllProduction (data) { | |
| return { | |
| type: GET_PRODUCTS | |
| data" data | |
| }); | |
| } | |
| ==== 其他 ===== | |
| const actions = bindActionCreators(ProductionActions, dispatch); | |
| 某個地方呼叫 ajax ,傳入已綁定好的 actions 如上 | |
| $.ajax('xxx/productions, { | |
| success: actions.getAllProduction | |
| } | |
| 流程:ajax -> ajax success callback -> action -> dispatch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment