From 1abc37403d5cb19cae70ed59083ac677e62c9edb Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sat, 18 Jul 2020 21:44:16 +0800 Subject: [PATCH] revert: tree watch logic --- components/vc-tree/src/Tree.jsx | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/components/vc-tree/src/Tree.jsx b/components/vc-tree/src/Tree.jsx index fa9634d39..b8e8fe4d7 100644 --- a/components/vc-tree/src/Tree.jsx +++ b/components/vc-tree/src/Tree.jsx @@ -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 ==================