-
Notifications
You must be signed in to change notification settings - Fork 45
Re-implement tree to work with giant structures #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This allows dropping metadata after the tree is built which reduces memory consumption.
Since this package is oriented to be as small as possible it is better to avoid ES6-only code. So instead of for..of it is better to use the old for loop.
# Conflicts: # __tests__/FixedSizeTree.spec.tsx # __tests__/VariableSizeTree.spec.tsx # src/Tree.tsx # src/VariableSizeTree.tsx # src/utils.ts
# Conflicts: # __tests__/FixedSizeTree.spec.tsx # __tests__/VariableSizeTree.spec.tsx # src/Tree.tsx
9345263 to
186ad4d
Compare
|
Kudos, SonarCloud Quality Gate passed!
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #11.
Fixes #30.
This is the first PR on the road to version 3. It introduces significant changes (including breaking) for the library.
Common description
The virtual tree system was completely rewritten to fit the new challenges of big tree structures. According to #11 and #30, changing the openness state in trees with about 1 million nodes freeze the UI for several seconds. With this rewrite I'm going to solve the problem. It provides a lot of tools to work with giant trees comfortably.
treeWalkermethod only for initial tree building and won't use it for openness state changes.requestIdleCallbackduring the build to reduce UI freezing for big trees.requestIdleCallbackas well.Breaking changes
treeWalkerThe
treeWalkerfunction has the completely different shape now.Old
treeWalkerworked for both initial tree building and changing node openness state:Old treeWalker
The new
treeWalkeris only for the tree building. TheTreecomponent builds and preserves the tree structure internally.New treeWalker
recomputeTreeThe
recomputeTreemethod has been completely re-worked. Now it is way more powerful than its predecessor, and the main role in this change is played bysubtreeCallbackfunction that applies to all descendants of the selected node. With it, you can do a lot of things including emulation of the olduseDefaultOpennessanduseDefaultHeightoptions.Old recomputeTree
New recomputeTree
Props
To allow working with
requestIdleCallbackand async actions, the PR introduces the following component properties.async: booleanThis option allows making the tree asynchronous; e.g. you will be able to load the branch data on the node opening. All it does under the hood is preserving the tree state between tree buildings on
treeWalkerupdate, so the user does not see the tree resetting to the default state when the async action is performed.If it is combined with the
placeholderoption, the tree re-building won't be interrupted by showing the placeholder; it will be shown only at the first time the tree is building.placeholder: ReactNode | nullThis property receives any react node that will be displayed instead of a tree during the building process. This option should only be used if the tree building process requires too much time (which means you have a really giant amount of data, e.g. about a million nodes).
Setting this option enables the
requestIdleCallbackunder the hood for browsers that support this feature. For other browsers the original scenario is applied; no placeholder will be shown.Using this feature allows avoiding UI freezes; however, it may slightly increase the time spent for the building process.
If you have an asynchronous giant tree and want to use profits of
requestIdleCallbackbut don't want placeholder to be shown on the first render (that is probably quite small because all other data will be loaded asynchronously), setplaceholdertonull. No placeholder will be shown on the first render but therequestIdleCallbackbuilding will be enabled and allow avoiding freezes on tree re-building when tree becomes bigger.buildingTaskTimeout: numberThis option works in tandem with the
placeholderoption. With it, you can set the task timeout for therequestIdleCallback. ThebuildingTaskTimeoutwill be sent directly as therequestIdleCallback'stimeoutoption.