Skip to content

Commit d4397bd

Browse files
committed
modelEnhance增加反回数据处理
1 parent 2f2a90e commit d4397bd

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/utils/modelEnhance.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ export default (model) => {
6666
* payload 如果传入数组形式的payload,会合并结果后调用一次渲染
6767
* success 在dispatch结束后得到成功的回调
6868
* error 在dispatch结束后得到失败的回调
69+
* afterResponse 模拟reduce中的操作,可以让我们有机会处理反回的数据,不能有副作用的方法
6970
*/
70-
* [REQUEST]({ payload, success, error }, { call, put }) {
71+
* [REQUEST]({ payload, success, error, afterResponse }, { call, put }) {
7172
let _payloads = [];
7273
if ($$.isObject(payload)) {
7374
_payloads.push(payload);
@@ -89,6 +90,12 @@ export default (model) => {
8990
try {
9091
let response = yield call(asyncRequest, otherPayload);
9192

93+
// 自已处理反回的数据,模拟reduce中的操作,这里不要写有副作用的函数
94+
if ($$.isFunction(afterResponse)) {
95+
let _r = afterResponse(response);
96+
if (_r) response = _r;
97+
}
98+
9299
// 如果需要回调
93100
if (otherPayload.success) {
94101
otherPayload.success(response);

0 commit comments

Comments
 (0)