async-fork
Dominic Gannaway 7 months ago
parent bfa2f3bc52
commit 91ef219980

@ -46,7 +46,7 @@ export function visit_event_attribute(node, context) {
// When we hoist a function we assign an array with the function and all
// hoisted closure params.
const args = [handler, b.id('$.active_effect'), ...hoisted_params];
const args = [handler, ...hoisted_params];
delegated_assignment = b.array(args);
} else {
delegated_assignment = handler;

@ -8,10 +8,8 @@ import * as w from '../../warnings.js';
import {
active_effect,
active_reaction,
event_boundary_effect,
set_active_effect,
set_active_reaction,
set_event_boundary_effect
set_active_reaction
} from '../../runtime.js';
import { without_reactive_context } from './bindings/shared.js';
import { get_boundary } from '../blocks/boundary.js';
@ -56,27 +54,18 @@ export function replay_events(dom) {
* @param {AddEventListenerOptions} [options]
*/
export function create_event(event_name, dom, handler, options = {}) {
var boundary_effect = (active_effect !== null && get_boundary(active_effect)) ?? null;
/**
* @this {EventTarget}
*/
function target_handler(/** @type {Event} */ event) {
var previous_boundary_effect = event_boundary_effect;
try {
if (boundary_effect !== null) {
set_event_boundary_effect(boundary_effect);
}
if (!options.capture) {
// Only call in the bubble phase, else delegated events would be called before the capturing events
handle_event_propagation.call(dom, event);
}
if (!event.cancelBubble) {
return without_reactive_context(() => {
return handler?.call(this, event);
});
}
} finally {
set_event_boundary_effect(previous_boundary_effect)
if (!options.capture) {
// Only call in the bubble phase, else delegated events would be called before the capturing events
handle_event_propagation.call(dom, event);
}
if (!event.cancelBubble) {
return without_reactive_context(() => {
return handler?.call(this, event);
});
}
}
@ -251,17 +240,8 @@ export function handle_event_propagation(event) {
if (delegated !== undefined && !(/** @type {any} */ (current_target).disabled)) {
if (is_array(delegated)) {
var [fn, effect, ...data] = delegated;
var boundary_effect = (effect !== null && get_boundary(effect)) ?? null;
var previous_boundary_effect = event_boundary_effect;
try {
if (boundary_effect !== null) {
set_event_boundary_effect(boundary_effect);
}
fn.apply(current_target, [event, ...data]);
} finally {
set_event_boundary_effect(previous_boundary_effect);
}
var [fn, ...data] = delegated;
fn.apply(current_target, [event, ...data]);
} else {
delegated.call(current_target, event);
}

@ -143,8 +143,7 @@ export {
untrack,
exclude_from_object,
deep_read,
deep_read_state,
active_effect
deep_read_state
} from './runtime.js';
export { validate_binding, validate_each_keys } from './validate.js';
export { raf } from './timing.js';

@ -173,12 +173,12 @@ export function internal_set(source, value) {
if (!source.equals(value)) {
possibly_fork(source);
mark_reactions(source, DIRTY);
var old_value = source.v;
source.v = value;
source.wv = increment_write_version();
mark_reactions(source, DIRTY);
if (DEV && tracing_mode_flag) {
source.updated = get_stack('UpdatedAt');
if (active_effect != null) {
@ -288,7 +288,7 @@ export function mark_reactions(signal, status, parent, only_boundary = false) {
continue;
}
}
} else if ((flags & (DERIVED | ASYNC_DERIVED)) === 0) {
} else if ((flags & (DERIVED | BLOCK_EFFECT)) === 0) {
boundary = get_boundary(/** @type {Effect} */ (reaction));
if (boundary) {
// @ts-ignore

@ -69,7 +69,10 @@ let is_micro_task_queued = false;
let last_scheduled_effect = null;
export let is_flushing_effect = false;
export let is_flushing_async_derived = false;
/** @type {Effect | null} */
export let flushing_effect = null;
export let is_destroying_effect = false;
/** @param {boolean} value */
@ -110,14 +113,6 @@ export function set_active_effect(effect) {
active_effect = effect;
}
/** @type {null | Effect} */
export let event_boundary_effect = null;
/** @param {null | Effect} effect */
export function set_event_boundary_effect(effect) {
event_boundary_effect = effect;
}
// TODO remove this, once we're satisfied that we're not leaking context
/* @__PURE__ */
setInterval(() => {
@ -842,12 +837,10 @@ function process_effects(effect, collected_effects) {
// to ensure that unowned deriveds are correctly tracked
// because we're flushing the current effect
var previous_active_reaction = active_reaction;
var previous_is_flushing_async_derived = is_flushing_async_derived;
var previous_flushing_effect = flushing_effect;
try {
active_reaction = current_effect;
if ((current_effect.f & ASYNC_DERIVED) !== 0) {
is_flushing_async_derived = true;
}
flushing_effect = current_effect;
if (check_dirtiness(current_effect)) {
update_effect(current_effect);
}
@ -855,7 +848,7 @@ function process_effects(effect, collected_effects) {
handle_error(error, current_effect, null, current_effect.ctx);
} finally {
active_reaction = previous_active_reaction;
is_flushing_async_derived = previous_is_flushing_async_derived;
flushing_effect = previous_flushing_effect;
}
}
@ -1029,14 +1022,12 @@ export function get(signal) {
var value = /** @type {V} */ (UNINITIALIZED);
var target_effect = event_boundary_effect ?? active_effect;
if (
target_effect !== null &&
!is_flushing_async_derived &&
(target_effect.f & ASYNC_DERIVED) === 0
active_effect !== null &&
(flushing_effect === null || (flushing_effect.f & (BLOCK_EFFECT | BRANCH_EFFECT)) === 0) &&
(active_effect.f & ASYNC_DERIVED) === 0
) {
var boundary = get_boundary(target_effect);
var boundary = get_boundary(active_effect);
if (boundary !== null) {
// @ts-ignore
var forks = boundary.fn.forks;

Loading…
Cancel
Save