Don't throw and catch useless errors in flush()

Inside flush(), we don't care if there is a current component or not, we
just want to save and restore it if there is one. Rather than throwing
and catching an error that would happen often, we'll just create another
version of get_current_component() that doesn't throw.
pull/6920/head
Robin Munn 5 years ago
parent 83e9cc5d5d
commit 47f90d0a1f

@ -11,6 +11,10 @@ export function get_current_component() {
return current_component;
}
export function maybe_get_current_component() {
return current_component;
}
export function beforeUpdate(fn: () => any) {
get_current_component().$$.before_update.push(fn);
}

@ -1,5 +1,5 @@
import { run_all } from './utils';
import { get_current_component, set_current_component } from './lifecycle';
import { maybe_get_current_component, set_current_component } from './lifecycle';
export const dirty_components = [];
export const intros = { enabled: false };
@ -35,12 +35,7 @@ const seen_callbacks = new Set();
let flushidx = 0; // Do *not* move this inside the flush() function
export function flush() {
let current_component = null;
try {
current_component = get_current_component();
} catch {
// no current component, so leave it as null
}
let current_component = maybe_get_current_component();
do {
// first, call beforeUpdate functions

Loading…
Cancel
Save