-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat: add basic render queueing #6851
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b9fa1dd
feat: add basic render queueing
BeksOmega 932c897
feat: change connecting and disconnecting to queue renders
BeksOmega fe65b97
feat: delay bringToFront
BeksOmega f0d2878
chore: format
BeksOmega ba6e715
chore: fix build
BeksOmega bae92de
fix: stop updating connections when setting the parent.
BeksOmega 08ae437
fix: connection highlight positioning
BeksOmega File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 file contains 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 file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import {BlockSvg} from './block_svg'; | ||
|
||
|
||
const rootBlocks = new Set<BlockSvg>(); | ||
const dirtyBlocks = new WeakSet<BlockSvg>(); | ||
let pid = 0; | ||
|
||
/** | ||
* Registers that the given block and all of its parents need to be rerendered, | ||
* and registers a callback to do so after a delay, to allowf or batching. | ||
* | ||
* @param block The block to rerender. | ||
* @internal | ||
*/ | ||
export function queueRender(block: BlockSvg) { | ||
queueBlock(block); | ||
if (!pid) pid = window.requestAnimationFrame(doRenders); | ||
} | ||
|
||
/** | ||
* Adds the given block and its parents to the render queue. Adds the root block | ||
* to the list of root blocks. | ||
* | ||
* @param block The block to queue. | ||
*/ | ||
function queueBlock(block: BlockSvg) { | ||
dirtyBlocks.add(block); | ||
const parent = block.getParent(); | ||
if (parent) { | ||
queueBlock(parent); | ||
} else { | ||
rootBlocks.add(block); | ||
} | ||
} | ||
|
||
/** | ||
* Rerenders all of the blocks in the queue. | ||
*/ | ||
function doRenders() { | ||
for (const block of rootBlocks) { | ||
if (block.isDisposed()) continue; | ||
renderBlock(block); | ||
} | ||
|
||
pid = 0; | ||
} | ||
|
||
/** | ||
* Recursively renders all of the children of the given block, and then renders | ||
* the block. | ||
BeksOmega marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @param block The block to rerender. | ||
*/ | ||
function renderBlock(block: BlockSvg) { | ||
for (const child of block.getChildren(false)) { | ||
renderBlock(child); | ||
} | ||
if (dirtyBlocks.has(block)) { | ||
dirtyBlocks.delete(block); | ||
rootBlocks.delete(block); | ||
block.render(false); | ||
} else { | ||
block.updateConnectionLocations(); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method doesn't have very many callers, and they are all in either
block_dragger.ts
orrendered_connection.ts
. Do you think indirecting viaBlockSvg.prototype.queueRender
(rather than callingrender_management.ts
'squeueRender
directly) is justified on redability or other grounds?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later changes make several more calls to this, so I think it is justified on grounds of readability. Plus, it's internal, so the maintainance cost to including it is minimal :P If we want to tear it out later we can!