MCPcopy Create free account
hub / github.com/adobe/react-spectrum / queueUpdate

Method queueUpdate

packages/react-aria/src/collections/Document.ts:572–597  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

570 }
571
572 queueUpdate(): void {
573 if (this.dirtyNodes.size === 0 || this.queuedRender) {
574 return;
575 }
576
577 // Only trigger subscriptions once during an update, when the first item changes.
578 // React's useSyncExternalStore will call getCollection immediately, to check whether the snapshot changed.
579 // If so, React will queue a render to happen after the current commit to our fake DOM finishes.
580 // We track whether getCollection is called in a subscription, and once it is called during render,
581 // we reset queuedRender back to false.
582 this.queuedRender = true;
583 this.inSubscription = true;
584
585 // Clone the collection to ensure that React queues a render. It will call getCollection again
586 // during render, at which point all the updates will be complete and we can return
587 // the new collection.
588 if (!this.isSSR) {
589 this.collection = this.collection.clone();
590 }
591
592 for (let fn of this.subscriptions) {
593 fn();
594 }
595
596 this.inSubscription = false;
597 }
598
599 subscribe(fn: () => void) {
600 this.subscriptions.add(fn);

Callers 4

appendChildMethod · 0.80
insertBeforeMethod · 0.80
removeChildMethod · 0.80
setPropsMethod · 0.80

Calls 2

fnFunction · 0.85
cloneMethod · 0.65

Tested by

no test coverage detected