Skip to content

Instantly share code, notes, and snippets.

@sorrycc
Created September 26, 2016 10:01
Show Gist options
  • Save sorrycc/72565f379a2f773dc543fa8cbe505daf to your computer and use it in GitHub Desktop.
Save sorrycc/72565f379a2f773dc543fa8cbe505daf to your computer and use it in GitHub Desktop.
dva-ast-result
{
"models": {
"list": [
{
"reducers": [
"Reducer^^./a/c.js^^add",
"Reducer^^./a/c.js^^minus"
],
"effects": [
"Effect^^./a/c.js^^addRemote"
],
"subscriptions": [
"Subscription^^./a/c.js^^setup"
],
"namespace": "count",
"state": 0,
"id": "Model^^./a/c.js^^count",
"filePath": "./a/c.js"
}
],
"reducerByIds": {
"Reducer^^./a/c.js^^add": {
"name": "add",
"source": "function(state) { return state + 1; }",
"id": "Reducer^^./a/c.js^^add",
"filePath": "./a/c.js"
},
"Reducer^^./a/c.js^^minus": {
"name": "minus",
"source": "function(state) { return state - 1; }",
"id": "Reducer^^./a/c.js^^minus",
"filePath": "./a/c.js"
}
},
"effectByIds": {
"Effect^^./a/c.js^^addRemote": {
"name": "addRemote",
"source": "function*() { yield put({ type: 'add' }); }",
"dispatches": [
"count/add"
],
"id": "Effect^^./a/c.js^^addRemote",
"filePath": "./a/c.js"
}
},
"subscriptionByIds": {
"Subscription^^./a/c.js^^setup": {
"name": "setup",
"source": "function() {\n dispatch({ type:'app/showLoading' });\n dispatch({ type:'addRemote' });\n}",
"dispatches": [
"app/showLoading",
"count/addRemote"
],
"id": "Subscription^^./a/c.js^^setup",
"filePath": "./a/c.js"
}
}
},
"router": {
"type": "Router",
"attributes": {
"history": "history"
},
"id": "Router-root",
"children": [
{
"type": "Route",
"attributes": {
"path": "/",
"component": "AppPage"
},
"absolutePath": "/",
"id": "Route-/",
"children": []
}
],
"filePath": "./a/c.js"
},
"routeComponents": [
{
"name": "Component",
"stateMappings": [
"count"
],
"dispatches": [
"count/minus"
],
"filepath": "./a/c.js",
"id": "RouteComponent^^./a/c.js^^Component"
}
],
"dispatches": {
"count/minus": {
"input": [
"RouteComponent^^./a/c.js^^Component"
],
"output": [
"Reducer^^./a/c.js^^minus"
]
},
"count/add": {
"input": [
"Effect^^./a/c.js^^addRemote"
],
"output": [
"Reducer^^./a/c.js^^add"
]
},
"count/addRemote": {
"input": [
"Subscription^^./a/c.js^^setup"
],
"output": [
"Effect^^./a/c.js^^addRemote"
]
},
"app/showLoading": {
"input": [
"Subscription^^./a/c.js^^setup"
],
"output": []
}
}
}
@sorrycc
Copy link
Author

sorrycc commented Sep 27, 2016

{
  "models": {
    "data": [
      {
        "reducers": [
          "Reducer^^models/app.js^^showLoading"
        ],
        "effects": [],
        "subscriptions": [],
        "namespace": "app",
        "state": {
          "loading": false
        },
        "id": "Model^^models/app.js^^app",
        "filePath": "models/app.js"
      },
      {
        "reducers": [
          "Reducer^^models/count.js^^add"
        ],
        "effects": [
          "Effect^^models/count.js^^addAsync"
        ],
        "subscriptions": [
          "Subscription^^models/count.js^^setup"
        ],
        "namespace": "count",
        "state": 0,
        "id": "Model^^models/count.js^^count",
        "filePath": "models/count.js"
      }
    ],
    "reducerByIds": {
      "Reducer^^models/app.js^^showLoading": {
        "name": "showLoading",
        "source": "function(state) {\n  return { ...state, loading: true, };\n}",
        "id": "Reducer^^models/app.js^^showLoading",
        "filePath": "models/app.js"
      },
      "Reducer^^models/count.js^^add": {
        "name": "add",
        "source": "function(state) {\n  return state + 1;\n}",
        "id": "Reducer^^models/count.js^^add",
        "filePath": "models/count.js"
      }
    },
    "effectByIds": {
      "Effect^^models/count.js^^addAsync": {
        "name": "addAsync",
        "source": "function*(_, { put, call, select }) {\n  yield put({ type: 'add' });\n}",
        "dispatches": [
          "count/add"
        ],
        "id": "Effect^^models/count.js^^addAsync",
        "filePath": "models/count.js"
      }
    },
    "subscriptionByIds": {
      "Subscription^^models/count.js^^setup": {
        "name": "setup",
        "source": "function({ dispatch }) {\n  dispatch({ type: 'app/showLoading' });\n  dispatch({ type: 'addAsync' });\n}",
        "dispatches": [
          "app/showLoading",
          "count/addAsync"
        ],
        "id": "Subscription^^models/count.js^^setup",
        "filePath": "models/count.js"
      }
    }
  },
  "router": {
    "type": "Router",
    "attributes": {
      "history": "history"
    },
    "id": "Router-root",
    "children": [
      {
        "type": "Route",
        "attributes": {
          "component": "App"
        },
        "id": "Route-parentId_Router-root",
        "children": []
      }
    ],
    "filePath": "router.js"
  },
  "dispatches": {
    "app/showLoading": {
      "input": [
        "Subscription^^models/count.js^^setup",
        "RouteComponent^^routes/App.js^^App"
      ],
      "output": [
        "Reducer^^models/app.js^^showLoading"
      ]
    },
    "count/add": {
      "input": [
        "Effect^^models/count.js^^addAsync",
        "RouteComponent^^routes/App.js^^App"
      ],
      "output": [
        "Reducer^^models/count.js^^add"
      ]
    },
    "count/addAsync": {
      "input": [
        "Subscription^^models/count.js^^setup"
      ],
      "output": [
        "Effect^^models/count.js^^addAsync"
      ]
    }
  },
  "routeComponents": [
    {
      "name": "App",
      "stateMappings": [],
      "dispatches": [
        "count/add",
        "app/showLoading"
      ],
      "filepath": "routes/App.js",
      "id": "RouteComponent^^routes/App.js^^App"
    }
  ]
}

@sorrycc
Copy link
Author

sorrycc commented Sep 27, 2016

routeComponents 的 source 我加下。

@sorrycc
Copy link
Author

sorrycc commented Sep 27, 2016

整理下变动点:

  1. dispatches 提供 input 和 output,指明输入和输出,便于关联修改
  2. id 规则为 类型+文件相对路径+name,以 ^^ 分隔
  3. filePath 改为相对路径
  4. models 结构调整,分 data, reducersById, effectsById, subscriptionsById,都放在 models 下是为了后面加入修改机制后便于修改

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment