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

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

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

Loading…
Cancel
Save