Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using shift in flush #4356

Merged
merged 2 commits into from
Feb 8, 2020
Merged
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
10 changes: 8 additions & 2 deletions src/runtime/internal/scheduler.ts
Original file line number Diff line number Diff line change
@@ -31,18 +31,23 @@ export function add_flush_callback(fn) {
flush_callbacks.push(fn);
}

let flushing = false;
const seen_callbacks = new Set();
export function flush() {
if (flushing) return;
flushing = true;

do {
// first, call beforeUpdate functions
// and update components
while (dirty_components.length) {
const component = dirty_components.shift();
for (let i = 0; i < dirty_components.length; i += 1) {
const component = dirty_components[i];
set_current_component(component);
update(component.$$);
}

dirty_components.length = 0;

while (binding_callbacks.length) binding_callbacks.pop()();

// then, once components are updated, call
@@ -67,6 +72,7 @@ export function flush() {
}

update_scheduled = false;
flushing = false;
seen_callbacks.clear();
}