Merge pull request #2555 from benlesh/scheduler-reuse-promise

perf: Reuse the same promise instance in the scheduler
pull/2558/head
Rich Harris 5 years ago committed by GitHub
commit ed7c32d12b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,21 +4,22 @@ import { set_current_component } from './lifecycle.js';
export const dirty_components = []; export const dirty_components = [];
export const intros = { enabled: false }; export const intros = { enabled: false };
let update_promise; const resolved_promise = Promise.resolve();
let update_scheduled = false;
const binding_callbacks = []; const binding_callbacks = [];
const render_callbacks = []; const render_callbacks = [];
const flush_callbacks = []; const flush_callbacks = [];
export function schedule_update() { export function schedule_update() {
if (!update_promise) { if (!update_scheduled) {
update_promise = Promise.resolve(); update_scheduled = true;
update_promise.then(flush); resolved_promise.then(flush);
} }
} }
export function tick() { export function tick() {
schedule_update(); schedule_update();
return update_promise; return resolved_promise;
} }
export function add_binding_callback(fn) { export function add_binding_callback(fn) {
@ -65,7 +66,7 @@ export function flush() {
flush_callbacks.pop()(); flush_callbacks.pop()();
} }
update_promise = null; update_scheduled = false;
} }
function update($$) { function update($$) {
@ -77,4 +78,4 @@ function update($$) {
$$.after_render.forEach(add_render_callback); $$.after_render.forEach(add_render_callback);
} }
} }

Loading…
Cancel
Save