Skip to content

Commit

Permalink
perf(check-tree-select): 优化大数据量下树选择器性能
Browse files Browse the repository at this point in the history
  • Loading branch information
zyprepare committed Sep 12, 2024
1 parent 6188997 commit f096bb6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-sheep-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

perf(check-tree-select): 优化大数据量下树选择器性能
5 changes: 5 additions & 0 deletions .changeset/stale-cougars-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/check-tree-select": patch
---

perf: 优化大数据量下树选择器性能
8 changes: 5 additions & 3 deletions packages/ui/check-tree-select/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { fFindNodeById, findNestedChildren, getNodeAncestors } from '@hi-ui/tree-utils'
import { findNestedChildren, getNodeAncestors } from '@hi-ui/tree-utils'
import { isArrayNonEmpty } from '@hi-ui/type-assertion'

/**
Expand All @@ -16,11 +16,12 @@ export const processCheckedIds = (
allowCheck: (node: any) => boolean
) => {
const keySet = new Set(checkedIds)
const flattedDataMap = new Map(flattenData.map((item: any) => [item.id, item]))

switch (type) {
case 'CHILD':
return checkedIds.filter((id) => {
const node = fFindNodeById(flattenData, id)
const node = flattedDataMap.get(id) as any

if (node) {
const { children } = node
Expand All @@ -38,7 +39,8 @@ export const processCheckedIds = (

case 'PARENT':
return checkedIds.filter((id) => {
const node = fFindNodeById(flattenData, id) as any
const node = flattedDataMap.get(id) as any

if (node) {
// 向上递归遍历是否被勾选
const ancestors = getNodeAncestors(node)
Expand Down

0 comments on commit f096bb6

Please sign in to comment.