Skip to content

Instantly share code, notes, and snippets.

@Jazznight
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save Jazznight/77b762d73c16c854cf26 to your computer and use it in GitHub Desktop.

Select an option

Save Jazznight/77b762d73c16c854cf26 to your computer and use it in GitHub Desktop.

Revisions

  1. @cswleocsw cswleocsw revised this gist Jul 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ export function getAllProduction () {

    2. 將 ajax 的行為都定義在其他地方, actions 只作簡單定義 ,例如 ProductionActions.js

    export function getAllProduction () {
    export function getAllProduction (data) {
    return {
    type: GET_PRODUCTS
    data" data
  2. @cswleocsw cswleocsw revised this gist Jul 30, 2015. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    1. 將 ajax 的行為都定義在 actions 裡,例如 ProductionActions.js

    export function getAllProduction () {
    @@ -37,5 +36,3 @@ $.ajax('xxx/productions, {
    }

    流程:ajax -> ajax success callback -> action -> dispatch

    以上,不曉得有沒有人知道我在問什麼?
  3. @cswleocsw cswleocsw created this gist Jul 30, 2015.
    41 changes: 41 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@

    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 () {
    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

    以上,不曉得有沒有人知道我在問什麼?