Skip to content

Commit

Permalink
Tree: fix ElemeFE#15538 by adding more detect logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
范文杰 committed May 19, 2019
1 parent 8933a05 commit 0413904
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/tree/src/model/node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import objectAssign from 'element-ui/src/utils/merge';
import { markNodeData, NODE_KEY } from './util';
import { arrayContains } from 'element-ui/src/utils/util';

export const getChildState = node => {
let all = true;
Expand Down Expand Up @@ -435,8 +436,10 @@ export default class Node {
const newNodes = [];

newData.forEach((item, index) => {
if (item[NODE_KEY]) {
newDataMap[item[NODE_KEY]] = { index, data: item };
const key = item[NODE_KEY];
const isNodeExists = !!key && arrayContains(oldData, data => data[NODE_KEY] === key);
if (isNodeExists) {
newDataMap[key] = { index, data: item };
} else {
newNodes.push({ index, data: item });
}
Expand Down
4 changes: 4 additions & 0 deletions src/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export const arrayFindIndex = function(arr, pred) {
return -1;
};

export const arrayContains = function(arr, pred) {
return arrayFindIndex(arr, pred) >= 0;
};

export const arrayFind = function(arr, pred) {
const idx = arrayFindIndex(arr, pred);
return idx !== -1 ? arr[idx] : undefined;
Expand Down

0 comments on commit 0413904

Please sign in to comment.