|
|
|
@ -757,17 +757,17 @@ let prev_event_type;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {{(): void;(): any;}} fn
|
|
|
|
* @param {{(): void;(): any;}} fn
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function yield_event_updates(fn) {
|
|
|
|
export function yield_event_updates(fn, flush_between_events = false) {
|
|
|
|
const event = window.event;
|
|
|
|
const event = window.event;
|
|
|
|
const previous_scheduler_mode = current_scheduler_mode;
|
|
|
|
const previous_scheduler_mode = current_scheduler_mode;
|
|
|
|
// If we're calling yield_updates and there is already an active yield in progress (`is_yield_task_active`)
|
|
|
|
// If we're calling yield_updates and there is already an active yield in progress (`is_yield_task_active`)
|
|
|
|
// and it has a different event type, then it's likely that a new event is about to occur that might try and read from the UI.
|
|
|
|
// and it has a different event type, then it's likely that a new event is about to occur that might try and read from the UI.
|
|
|
|
// Additionally, we might be dealing with a case where we explicitly want to flush if `event.isTrusted` is true and
|
|
|
|
// Additionally, we might be dealing with a case where we explicitly want to flush if `event.isTrusted` is true and
|
|
|
|
// `is_yield_task_queued`, for example if we had an event like `submit`, that occured because of a `click`.
|
|
|
|
// `flush_between_events` is enabled, for example if we had an event like `submit`, that occured because of a `click`.
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
previous_scheduler_mode !== FLUSH_YIELD &&
|
|
|
|
previous_scheduler_mode !== FLUSH_YIELD &&
|
|
|
|
((is_yield_task_active && prev_event_type !== event?.type) ||
|
|
|
|
((is_yield_task_active && prev_event_type !== event?.type) ||
|
|
|
|
(is_yield_task_queued && event?.isTrusted))
|
|
|
|
(is_yield_task_queued && flush_between_events && event?.isTrusted))
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
flush_sync();
|
|
|
|
flush_sync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|