如果没有变化,不要去更新store,避免没必要的重绘

This commit is contained in:
2betop 2020-05-08 17:50:39 +08:00
parent fe2b931e7c
commit 7fa8adec80
3 changed files with 28 additions and 11 deletions

View File

@ -408,7 +408,7 @@ export default class Table extends React.Component<TableProps, object> {
item.change(values, savePristine);
// 值发生变化了,需要通过 onSelect 通知到外面,否则会出现数据不同步的问题
this.syncSelected();
item.modified && this.syncSelected();
if ((!saveImmediately && !propsSaveImmediately) || savePristine) {
return;

View File

@ -21,7 +21,8 @@ import {
findTree,
flattenTree,
eachTree,
difference
difference,
immutableExtends
} from '../utils/helper';
import {evalExpression} from '../utils/tpl';
@ -159,15 +160,8 @@ export const Row = types
},
change(values: object, savePristine?: boolean) {
self.data = {
...self.data,
...values
};
savePristine &&
(self.pristine = {
...self.data
});
self.data = immutableExtends(self.data, values);
savePristine && (self.pristine = self.data);
},
reset() {

View File

@ -331,6 +331,29 @@ export function isArrayChildrenModified(
return false;
}
export function immutableExtends(to: any, from: any, deep = false) {
// 不是对象不可以merge
if (!isObject(to) || !isObject(from)) {
return to;
}
let ret = to;
Object.keys(from).forEach(key => {
const origin = to[key];
const value = to[key];
// todo 支持深度merge
if (origin !== value) {
// 一旦有修改,就创建个新对象。
ret = ret !== to ? ret : {...to};
ret[key] = value;
}
});
return ret;
}
// 即将抛弃
export function makeColumnClassBuild(
steps: number,