不要直接覆盖原有属性

This commit is contained in:
liaoxuezhi 2019-07-29 14:29:00 +08:00
parent 66d3041e92
commit 8783ce1c21
3 changed files with 14 additions and 8 deletions

View File

@ -8,7 +8,7 @@ import { SchemaNode, Schema, Action } from '../types';
import { filter } from '../utils/tpl';
import Modal from '../components/Modal';
import findLast = require('lodash/findLast');
import { guid } from '../utils/helper';
import { guid, chainFunctions } from '../utils/helper';
import { reaction } from 'mobx';
import { closeIcon } from '../components/icons';
import { ModalStore, IModalStore } from '../store/modal';
@ -289,9 +289,9 @@ export default class Dialog extends React.Component<DialogProps, DialogState> {
};
// 同步数据到 Dialog 层,方便 actions 根据表单数据联动。
subProps.onChange = this.handleFormChange;
subProps.onInit = this.handleFormInit;
subProps.onSaved = this.handleFormSaved;
subProps.onChange = chainFunctions(this.handleFormChange, schema.onChange);
subProps.onInit = chainFunctions(this.handleFormInit, schema.onInit);
subProps.onSaved = chainFunctions(this.handleFormSaved, schema.onSaved);
}
return render(`body${key ? `/${key}` : ''}`, schema, subProps);

View File

@ -8,7 +8,7 @@ import {SchemaNode, Schema, Action} from '../types';
import cx from 'classnames';
import {default as DrawerContainer} from '../components/Drawer';
import findLast = require('lodash/findLast');
import {guid} from '../utils/helper';
import {guid, chainFunctions} from '../utils/helper';
import {reaction} from 'mobx';
import {findDOMNode} from 'react-dom';
import {IModalStore, ModalStore} from '../store/modal';
@ -258,9 +258,9 @@ export default class Drawer extends React.Component<DrawerProps, object> {
};
// 同步数据到 Dialog 层,方便 actions 根据表单数据联动。
subProps.onChange = this.handleFormChange;
subProps.onInit = this.handleFormInit;
subProps.onSaved = this.handleFormSaved;
subProps.onChange = chainFunctions(this.handleFormChange, schema.onChange);
subProps.onInit = chainFunctions(this.handleFormInit, schema.onInit);
subProps.onSaved = chainFunctions(this.handleFormSaved, schema.onSaved);
}
return render(`body${key ? `/${key}` : ''}`, schema, subProps);

View File

@ -692,4 +692,10 @@ export function object2formData(data:any, options:any = {
parts[0] && fd.append(parts[0], parts[1]);
});
return fd;
}
export function chainFunctions(...fns:Array<(...args:Array<any>) => void>):(...args:Array<any>) => void {
return (...args:Array<any>) => {
fns.forEach(fn => fn && fn(...args));
}
}