Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
}

/**
Expand Down
37 changes: 13 additions & 24 deletions packages/svelte/src/internal/client/transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 2 additions & 8 deletions packages/svelte/src/main/main-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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
Expand Down