avoid using .shift() in flush() (#4356)

pull/4391/head
Jordan Gensler 6 years ago committed by GitHub
parent a40f4ad5e3
commit 4b04b16fe0

@ -31,18 +31,23 @@ export function add_flush_callback(fn) {
flush_callbacks.push(fn); flush_callbacks.push(fn);
} }
let flushing = false;
const seen_callbacks = new Set(); const seen_callbacks = new Set();
export function flush() { export function flush() {
if (flushing) return;
flushing = true;
do { do {
// first, call beforeUpdate functions // first, call beforeUpdate functions
// and update components // and update components
while (dirty_components.length) { for (let i = 0; i < dirty_components.length; i += 1) {
const component = dirty_components.shift(); const component = dirty_components[i];
set_current_component(component); set_current_component(component);
update(component.$$); update(component.$$);
} }
dirty_components.length = 0;
while (binding_callbacks.length) binding_callbacks.pop()(); while (binding_callbacks.length) binding_callbacks.pop()();
// then, once components are updated, call // then, once components are updated, call
@ -67,6 +72,7 @@ export function flush() {
} }
update_scheduled = false; update_scheduled = false;
flushing = false;
seen_callbacks.clear(); seen_callbacks.clear();
} }

Loading…
Cancel
Save