revert: tree watch logic

pull/2682/head
tangjinzhou 2020-07-18 21:44:16 +08:00
parent 61b5bfa0f6
commit 1abc37403d
1 changed files with 23 additions and 10 deletions

View File

@ -27,6 +27,16 @@ import {
* other props can pass with context for future refactor.
*/
function getWatch(keys = []) {
const watch = {};
keys.forEach(k => {
watch[k] = function() {
this.needSyncKeys[k] = true;
};
});
return watch;
}
const Tree = {
name: 'Tree',
inheritAttrs: false,
@ -129,17 +139,19 @@ const Tree = {
},
watch: {
// ...getWatch([
// 'treeData',
// 'children',
// 'expandedKeys',
// 'autoExpandParent',
// 'selectedKeys',
// 'checkedKeys',
// 'loadedKeys',
// ]),
// watch
...getWatch([
'treeData',
'children',
'expandedKeys',
'autoExpandParent',
'selectedKeys',
'checkedKeys',
'loadedKeys',
]),
__propsSymbol__() {
this.setState(this.getDerivedState(getOptionProps(this), this.$data));
this.needSyncKeys = {};
},
},
@ -149,8 +161,9 @@ const Tree = {
const newState = {
_prevProps: { ...props },
};
const self = this;
function needSync(name) {
return (!_prevProps && name in props) || (_prevProps && _prevProps[name] !== props[name]);
return (!_prevProps && name in props) || (_prevProps && self.needSyncKeys[name]);
}
// ================== Tree Node ==================