Skip to content

Commit

Permalink
fix: tree expandedKeys push #239 (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou authored Dec 5, 2018
1 parent 8e37cd8 commit 65311fb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions components/vc-tree/src/Tree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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',
mixins: [BaseMixin],
Expand Down Expand Up @@ -91,6 +101,7 @@ const Tree = {
}),

data () {
this.needSyncKeys = {}
const state = {
_posEntities: {},
_keyEntities: {},
Expand Down Expand Up @@ -124,8 +135,10 @@ const Tree = {
},

watch: {
...getWatch(['treeData', 'children', 'expandedKeys', 'autoExpandParent', 'selectedKeys', 'checkedKeys', 'loadedKeys']),
__propsSymbol__ () {
this.setState(this.getDerivedStateFromProps(getOptionProps(this), this.$data))
this.needSyncKeys = {}
},
},

Expand All @@ -135,9 +148,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 ==================
Expand Down

0 comments on commit 65311fb

Please sign in to comment.