chore: replace queue_idle_task with queue_micro_task

remove-idle-tasks
Rich Harris 6 hours ago
parent b92a55994b
commit e874139fc1

@ -6,7 +6,7 @@ import { create_event, delegate } from './events.js';
import { add_form_reset_listener, autofocus } from './misc.js'; import { add_form_reset_listener, autofocus } from './misc.js';
import * as w from '../../warnings.js'; import * as w from '../../warnings.js';
import { LOADING_ATTR_SYMBOL } from '#client/constants'; import { LOADING_ATTR_SYMBOL } from '#client/constants';
import { queue_idle_task } from '../task.js'; import { queue_micro_task } from '../task.js';
import { is_capture_event, is_delegated, normalize_attribute } from '../../../../utils.js'; import { is_capture_event, is_delegated, normalize_attribute } from '../../../../utils.js';
import { import {
active_effect, active_effect,
@ -65,7 +65,7 @@ export function remove_input_defaults(input) {
// @ts-expect-error // @ts-expect-error
input.__on_r = remove_defaults; input.__on_r = remove_defaults;
queue_idle_task(remove_defaults); queue_micro_task(remove_defaults);
add_form_reset_listener(); add_form_reset_listener();
} }

@ -1,32 +1,17 @@
import { run_all } from '../../shared/utils.js'; import { run_all } from '../../shared/utils.js';
import { is_flushing_sync } from '../reactivity/batch.js'; import { is_flushing_sync } from '../reactivity/batch.js';
// Fallback for when requestIdleCallback is not available
const request_idle_callback =
typeof requestIdleCallback === 'undefined'
? (/** @type {() => void} */ cb) => setTimeout(cb, 1)
: requestIdleCallback;
/** @type {Array<() => void>} */ /** @type {Array<() => void>} */
let micro_tasks = []; let micro_tasks = [];
/** @type {Array<() => void>} */
let idle_tasks = [];
function run_micro_tasks() { function run_micro_tasks() {
var tasks = micro_tasks; var tasks = micro_tasks;
micro_tasks = []; micro_tasks = [];
run_all(tasks); run_all(tasks);
} }
function run_idle_tasks() {
var tasks = idle_tasks;
idle_tasks = [];
run_all(tasks);
}
export function has_pending_tasks() { export function has_pending_tasks() {
return micro_tasks.length > 0 || idle_tasks.length > 0; return micro_tasks.length > 0;
} }
/** /**
@ -51,17 +36,6 @@ export function queue_micro_task(fn) {
micro_tasks.push(fn); micro_tasks.push(fn);
} }
/**
* @param {() => void} fn
*/
export function queue_idle_task(fn) {
if (idle_tasks.length === 0) {
request_idle_callback(run_idle_tasks);
}
idle_tasks.push(fn);
}
/** /**
* Synchronously run any queued tasks. * Synchronously run any queued tasks.
*/ */
@ -69,8 +43,4 @@ export function flush_tasks() {
if (micro_tasks.length > 0) { if (micro_tasks.length > 0) {
run_micro_tasks(); run_micro_tasks();
} }
if (idle_tasks.length > 0) {
run_idle_tasks();
}
} }

Loading…
Cancel
Save