always push

each-branch-manager
Rich Harris 1 day ago
parent 369023389c
commit 32cefa280b

@ -80,10 +80,9 @@ function push_effect(effect, parent_effect) {
* @param {number} type * @param {number} type
* @param {null | (() => void | (() => void))} fn * @param {null | (() => void | (() => void))} fn
* @param {boolean} sync * @param {boolean} sync
* @param {boolean} push
* @returns {Effect} * @returns {Effect}
*/ */
function create_effect(type, fn, sync, push = true) { function create_effect(type, fn, sync) {
var parent = active_effect; var parent = active_effect;
if (DEV) { if (DEV) {
@ -133,46 +132,42 @@ function create_effect(type, fn, sync, push = true) {
schedule_effect(effect); schedule_effect(effect);
} }
if (push) { /** @type {Effect | null} */
/** @type {Effect | null} */ var e = effect;
var e = effect;
// if an effect has already ran and doesn't need to be kept in the tree // if an effect has already ran and doesn't need to be kept in the tree
// (because it won't re-run, has no DOM, and has no teardown etc) // (because it won't re-run, has no DOM, and has no teardown etc)
// then we skip it and go to its child (if any) // then we skip it and go to its child (if any)
if ( if (
sync && sync &&
e.deps === null && e.deps === null &&
e.teardown === null && e.teardown === null &&
e.nodes_start === null && e.nodes_start === null &&
e.first === e.last && // either `null`, or a singular child e.first === e.last && // either `null`, or a singular child
(e.f & EFFECT_PRESERVED) === 0 (e.f & EFFECT_PRESERVED) === 0
) { ) {
e = e.first; e = e.first;
if ((type & BLOCK_EFFECT) !== 0 && (type & EFFECT_TRANSPARENT) !== 0 && e !== null) { if ((type & BLOCK_EFFECT) !== 0 && (type & EFFECT_TRANSPARENT) !== 0 && e !== null) {
e.f |= EFFECT_TRANSPARENT; e.f |= EFFECT_TRANSPARENT;
}
} }
}
if (e !== null) { if (e !== null) {
e.parent = parent; e.parent = parent;
if (parent !== null) { if (parent !== null) {
push_effect(e, parent); push_effect(e, parent);
} }
// if we're in a derived, add the effect there too // if we're in a derived, add the effect there too
if ( if (
active_reaction !== null && active_reaction !== null &&
(active_reaction.f & DERIVED) !== 0 && (active_reaction.f & DERIVED) !== 0 &&
(type & ROOT_EFFECT) === 0 (type & ROOT_EFFECT) === 0
) { ) {
var derived = /** @type {Derived} */ (active_reaction); var derived = /** @type {Derived} */ (active_reaction);
(derived.effects ??= []).push(e); (derived.effects ??= []).push(e);
}
} }
} else {
console.trace('not pushing');
} }
return effect; return effect;
@ -388,13 +383,11 @@ export function block(fn, flags = 0) {
return effect; return effect;
} }
// TODO i think we don't need `push` any more?
/** /**
* @param {(() => void)} fn * @param {(() => void)} fn
* @param {boolean} [push]
*/ */
export function branch(fn, push = true) { export function branch(fn) {
return create_effect(BRANCH_EFFECT | EFFECT_PRESERVED, fn, true, push); return create_effect(BRANCH_EFFECT | EFFECT_PRESERVED, fn, true);
} }
/** /**

Loading…
Cancel
Save