chore: simplify code (#10294)

* chore: simplify code

* a few more

* constify

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/10290/head
Rich Harris 8 months ago committed by GitHub
parent 821a213636
commit 07a0ae449b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1420,13 +1420,10 @@ export function user_effect(init) {
!apply_component_effect_heuristics !apply_component_effect_heuristics
); );
if (apply_component_effect_heuristics) { if (apply_component_effect_heuristics) {
let effects = /** @type {import('./types.js').ComponentContext} */ (current_component_context) const context = /** @type {import('./types.js').ComponentContext} */ (
.e; current_component_context
if (effects === null) { );
effects = /** @type {import('./types.js').ComponentContext} */ (current_component_context).e = (context.e ??= []).push(effect);
[];
}
effects.push(effect);
} }
return effect; return effect;
} }
@ -1744,12 +1741,7 @@ export function get_or_init_context_map() {
(DEV ? 'Context can only be used during component initialisation.' : '') (DEV ? 'Context can only be used during component initialisation.' : '')
); );
} }
let context_map = component_context.c; return (component_context.c ??= new Map(get_parent_context(component_context) || undefined));
if (context_map === null) {
const parent_context = get_parent_context(component_context);
context_map = component_context.c = new Map(parent_context || undefined);
}
return context_map;
} }
/** /**

@ -683,10 +683,7 @@ function if_block_transition(transition) {
const block = this; const block = this;
// block.value === true // block.value === true
if (block.v) { if (block.v) {
let consequent_transitions = block.c; const consequent_transitions = (block.c ??= new Set());
if (consequent_transitions === null) {
consequent_transitions = block.c = new Set();
}
consequent_transitions.add(transition); consequent_transitions.add(transition);
transition.f(() => { transition.f(() => {
const c = /** @type {Set<import('./types.js').Transition>} */ (consequent_transitions); const c = /** @type {Set<import('./types.js').Transition>} */ (consequent_transitions);
@ -697,10 +694,7 @@ function if_block_transition(transition) {
} }
}); });
} else { } else {
let alternate_transitions = block.a; const alternate_transitions = (block.a ??= new Set());
if (alternate_transitions === null) {
alternate_transitions = block.a = new Set();
}
alternate_transitions.add(transition); alternate_transitions.add(transition);
transition.f(() => { transition.f(() => {
const a = /** @type {Set<import('./types.js').Transition>} */ (alternate_transitions); const a = /** @type {Set<import('./types.js').Transition>} */ (alternate_transitions);
@ -732,25 +726,20 @@ function each_item_transition(transition) {
if (transition.r === 'key' && (each_block.f & EACH_IS_ANIMATED) === 0) { if (transition.r === 'key' && (each_block.f & EACH_IS_ANIMATED) === 0) {
each_block.f |= EACH_IS_ANIMATED; each_block.f |= EACH_IS_ANIMATED;
} }
let transitions = block.s; const transitions = (block.s ??= new Set());
if (transitions === null) {
block.s = transitions = new Set();
}
transition.f(() => { transition.f(() => {
if (transitions !== null) { transitions.delete(transition);
transitions.delete(transition); if (transition.r !== 'key') {
if (transition.r !== 'key') { for (let other of transitions) {
for (let other of transitions) { const type = other.r;
const type = other.r; if (type === 'key' || type === 'in') {
if (type === 'key' || type === 'in') { transitions.delete(other);
transitions.delete(other);
}
}
if (transitions.size === 0) {
block.s = null;
destroy_each_item_block(block, null, true);
} }
} }
if (transitions.size === 0) {
block.s = null;
destroy_each_item_block(block, null, true);
}
} }
}); });
transitions.add(transition); transitions.add(transition);

@ -215,10 +215,7 @@ export function beforeUpdate(fn) {
throw new Error('beforeUpdate can only be used during component initialisation.'); throw new Error('beforeUpdate can only be used during component initialisation.');
} }
if (component_context.u === null) { (component_context.u ??= init_update_callbacks()).b.push(fn);
component_context.u = init_update_callbacks();
}
component_context.u.b.push(fn);
} }
/** /**
@ -239,10 +236,7 @@ export function afterUpdate(fn) {
throw new Error('afterUpdate can only be used during component initialisation.'); throw new Error('afterUpdate can only be used during component initialisation.');
} }
if (component_context.u === null) { (component_context.u ??= init_update_callbacks()).a.push(fn);
component_context.u = init_update_callbacks();
}
component_context.u.a.push(fn);
} }
// TODO bring implementations in here // TODO bring implementations in here

Loading…
Cancel
Save