File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -930,41 +930,42 @@ export class TreeStore {
930930 // 所在判断过滤条件是否存在之前,就要调用这里的清理逻辑
931931 // 不想在每次渲染时都做这个清空判断
932932 // 所以判断一下之前是否有进行过滤
933- allNodes . forEach ( ( node : TreeNode ) => {
933+ for ( let i = 0 ; i < allNodes . length ; i ++ ) {
934+ const node = allNodes [ i ] ;
934935 // 先清空所有锁定状态
935936 if ( node . vmIsLocked ) {
936937 // lock 方法内部有状态计算
937938 // 所以要减少 lock 方法调用次数
938939 node . lock ( false ) ;
939940 }
940- } ) ;
941+ }
941942 }
942943
943944 const currentFilter = config . filter ;
944945 // 当前没有过滤器
945946 // 则无需处理锁定节点
946947 if ( ! currentFilter || ! isFunction ( currentFilter ) ) return ;
947- this . prevFilter = config . filter ;
948+ this . prevFilter = currentFilter ;
948949
950+ // 数据量大时,for 比 forEach 性能更好
949951 // 全部节点要经过排序,才能使用这个遍历
950952 // 比起每个过滤节点调用 getParents 方法检查父节点状态
951953 // 复杂度 O(N*log(N)) => O(N)
952- allNodes . reverse ( ) . forEach ( ( node : TreeNode ) => {
953- // 数组颠倒后,等于是从每个节点的子节点开始判断
954- // 想象为从展开树的最底部向上遍历
954+ for ( let i = allNodes . length - 1 ; i >= 0 ; i -- ) {
955+ const node = allNodes [ i ] ;
955956 const parent = node . getParent ( ) ;
956- if ( ! parent ) return ;
957+ if ( ! parent ) continue ;
958+ // 当前节点被过滤条件命中
959+ // 或者当前节点被锁定
960+ // 则需要判定父节点状态
957961 if ( node . vmIsRest || node . vmIsLocked ) {
958- // 当前节点被过滤条件命中
959- // 或者当前节点被锁定
960- // 则需要判定父节点状态
961962 if ( ! parent . vmIsLocked ) {
962963 // 父节点已被锁定,则忽略动作
963964 // lock 方法有内置状态判断
964965 parent . lock ( true ) ;
965966 }
966967 }
967- } ) ;
968+ }
968969 }
969970}
970971
You can’t perform that action at this time.
0 commit comments