return promise from nextTick

pull/2030/head
Rich Harris 6 years ago
parent 0172d84850
commit fb534a3d50

@ -4,14 +4,13 @@ import { set_current_component } from './lifecycle.js';
export let dirty_components = []; export let dirty_components = [];
export const intros = { enabled: false }; export const intros = { enabled: false };
let update_scheduled = false; let update_promise;
const binding_callbacks = []; const binding_callbacks = [];
const render_callbacks = []; const render_callbacks = [];
export function schedule_update() { export function schedule_update() {
if (!update_scheduled) { if (!update_promise) {
update_scheduled = true; update_promise = Promise.resolve().then(flush);
queue_microtask(flush);
} }
} }
@ -22,6 +21,7 @@ export function add_render_callback(fn) {
export function nextTick(fn) { export function nextTick(fn) {
add_render_callback(fn); add_render_callback(fn);
schedule_update(); schedule_update();
return update_promise;
} }
export function add_binding_callback(fn) { export function add_binding_callback(fn) {
@ -56,7 +56,7 @@ export function flush() {
} }
} while (dirty_components.length); } while (dirty_components.length);
update_scheduled = false; update_promise = null;
} }
function update($$) { function update($$) {
@ -69,9 +69,3 @@ function update($$) {
$$.after_render.forEach(add_render_callback); $$.after_render.forEach(add_render_callback);
} }
} }
function queue_microtask(callback) {
Promise.resolve().then(() => {
if (update_scheduled) callback();
});
}
Loading…
Cancel
Save