Skip to content

Commit

Permalink
Rename yieldToMain to splitTask
Browse files Browse the repository at this point in the history
Co-authored-by: tunetheweb <[email protected]>
  • Loading branch information
westonruter and tunetheweb committed Jun 20, 2024
1 parent 7c17304 commit 677ad2a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
12 changes: 3 additions & 9 deletions packages/interactivity/src/directives.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ import { deepSignal, peek, type DeepSignal } from 'deepsignal';
/**
* Internal dependencies
*/
import {
useWatch,
useInit,
kebabToCamelCase,
warn,
yieldToMain,
} from './utils';
import { useWatch, useInit, kebabToCamelCase, warn, splitTask } from './utils';
import type { DirectiveEntry } from './hooks';
import { directive, getScope, getEvaluate } from './hooks';

Expand Down Expand Up @@ -246,7 +240,7 @@ const getGlobalAsyncEventDirective = ( type: 'window' | 'document' ) => {
const eventName = entry.suffix.split( '--', 1 )[ 0 ];
useInit( () => {
const cb = async ( event: Event ) => {
await yieldToMain();
await splitTask();
evaluate( entry, event );
};
const globalVar = type === 'window' ? window : document;
Expand Down Expand Up @@ -361,7 +355,7 @@ export default () => {
existingHandler( event );
}
entries.forEach( async ( entry ) => {
await yieldToMain();
await splitTask();
evaluate( entry, event );
} );
};
Expand Down
2 changes: 1 addition & 1 deletion packages/interactivity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export {
useLayoutEffect,
useCallback,
useMemo,
yieldToMain,
splitTask,
} from './utils';

export { useState, useRef } from 'preact/hooks';
Expand Down
6 changes: 3 additions & 3 deletions packages/interactivity/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { hydrate, type ContainerNode, type ComponentChild } from 'preact';
* Internal dependencies
*/
import { toVdom, hydratedIslands } from './vdom';
import { createRootFragment, yieldToMain } from './utils';
import { createRootFragment, splitTask } from './utils';
import { directivePrefix } from './constants';

// Keep the same root fragment for each interactive region node.
Expand Down Expand Up @@ -35,11 +35,11 @@ export const init = async () => {

for ( const node of nodes ) {
if ( ! hydratedIslands.has( node ) ) {
await yieldToMain();
await splitTask();
const fragment = getRegionRootFragment( node );
const vdom = toVdom( node );
initialVdom.set( node, vdom );
await yieldToMain();
await splitTask();
hydrate( vdom, fragment );
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/interactivity/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const afterNextFrame = ( callback: () => void ) => {
*
* @return Promise
*/
export const yieldToMain = () => {
export const splitTask = () => {
return new Promise( ( resolve ) => {
// TODO: Use scheduler.yield() when available.
setTimeout( resolve, 0 );
Expand Down

0 comments on commit 677ad2a

Please sign in to comment.