66
77import { BlockSvg } from './block_svg.js' ;
88import * as userAgent from './utils/useragent.js' ;
9+ import type { WorkspaceSvg } from './workspace_svg.js' ;
910
1011/** The set of all blocks in need of rendering which don't have parents. */
1112const rootBlocks = new Set < BlockSvg > ( ) ;
1213
1314/** The set of all blocks in need of rendering. */
14- let dirtyBlocks = new WeakSet < BlockSvg > ( ) ;
15+ const dirtyBlocks = new WeakSet < BlockSvg > ( ) ;
1516
1617/**
1718 * The promise which resolves after the current set of renders is completed. Or
@@ -75,12 +76,14 @@ export function finishQueuedRenders(): Promise<void> {
7576 * cases where queueing renders breaks functionality + backwards compatibility
7677 * (such as rendering icons).
7778 *
79+ * @param workspace If provided, only rerender blocks in this workspace.
80+ *
7881 * @internal
7982 */
80- export function triggerQueuedRenders ( ) {
81- window . cancelAnimationFrame ( animationRequestId ) ;
82- doRenders ( ) ;
83- if ( afterRendersResolver ) afterRendersResolver ( ) ;
83+ export function triggerQueuedRenders ( workspace ?: WorkspaceSvg ) {
84+ if ( ! workspace ) window . cancelAnimationFrame ( animationRequestId ) ;
85+ doRenders ( workspace ) ;
86+ if ( ! workspace && afterRendersResolver ) afterRendersResolver ( ) ;
8487}
8588
8689/**
@@ -110,10 +113,16 @@ function queueBlock(block: BlockSvg) {
110113
111114/**
112115 * Rerenders all of the blocks in the queue.
116+ *
117+ * @param workspace If provided, only rerender blocks in this workspace.
113118 */
114- function doRenders ( ) {
115- const workspaces = new Set ( [ ...rootBlocks ] . map ( ( block ) => block . workspace ) ) ;
116- const blocks = [ ...rootBlocks ] . filter ( shouldRenderRootBlock ) ;
119+ function doRenders ( workspace ?: WorkspaceSvg ) {
120+ const workspaces = workspace
121+ ? new Set ( [ workspace ] )
122+ : new Set ( [ ...rootBlocks ] . map ( ( block ) => block . workspace ) ) ;
123+ const blocks = [ ...rootBlocks ]
124+ . filter ( shouldRenderRootBlock )
125+ . filter ( ( b ) => workspaces . has ( b . workspace ) ) ;
117126 for ( const block of blocks ) {
118127 renderBlock ( block ) ;
119128 }
@@ -125,9 +134,19 @@ function doRenders() {
125134 block . updateComponentLocations ( blockOrigin ) ;
126135 }
127136
128- rootBlocks . clear ( ) ;
129- dirtyBlocks = new Set ( ) ;
130- afterRendersPromise = null ;
137+ for ( const block of blocks ) {
138+ dequeueBlock ( block ) ;
139+ }
140+ if ( ! workspace ) afterRendersPromise = null ;
141+ }
142+
143+ /** Removes the given block and children from the render queue. */
144+ function dequeueBlock ( block : BlockSvg ) {
145+ rootBlocks . delete ( block ) ;
146+ dirtyBlocks . delete ( block ) ;
147+ for ( const child of block . getChildren ( false ) ) {
148+ dequeueBlock ( child ) ;
149+ }
131150}
132151
133152/**
0 commit comments