pull/4742/head
pushkine 6 years ago
parent 431f567908
commit 654bcfda7e

@ -51,7 +51,10 @@ function add(c) {
}
const timed_tasks = [];
// callback on 1st frame after timestamp
/**
* Callback on 1st frame after timestamp
*/
export function raf_timeout(callback: () => void, timestamp: number) {
let i = timed_tasks.length;
let v;
@ -70,14 +73,12 @@ export function raf_timeout(callback: () => void, timestamp: number) {
// pop() until now < task.timestamp
timed_tasks.pop().c(now);
}
console.log(i, timed_tasks, now);
return timed_tasks.length;
});
}
return () => {
const index = timed_tasks.indexOf(task);
if (~index) timed_tasks.splice(index, 1);
console.log(timed_tasks);
};
}
export function loopThen(delay: number, run: (now: number) => void, stop: () => void, end_time: number) {
@ -88,6 +89,3 @@ export function loopThen(delay: number, run: (now: number) => void, stop: () =>
return () => cancel();
}
}
export function next_frame(callback) {
return add(() => (callback(), false));
}

@ -32,71 +32,38 @@ export function add_flush_callback(fn) {
let flushing = false;
const seen_callbacks = new Set();
// export function flush() {
// if (flushing) return;
// flushing = true;
// do {
// // update components + beforeUpdate
// for (let i = 0, component; i < dirty_components.length; i++) {
// set_current_component((component = dirty_components[i]));
// update(component.$$);
// }
// dirty_components.length = 0;
// // update bindings
// for (let i = 0; i < binding_callbacks.length; i++) {
// binding_callbacks[i]();
// }
// binding_callbacks.length = 0;
// // afterUpdate
// for (let i = 0, callback; i < render_callbacks.length; i++) {
// if (seen_callbacks.has((callback = render_callbacks[i]))) continue;
// seen_callbacks.add(callback);
// callback();
// }
// render_callbacks.length = 0;
// } while (dirty_components.length);
// for (let i = 0; i < flush_callbacks.length; i++) {
// flush_callbacks[i]();
// }
// flush_callbacks.length = 0;
// update_scheduled = false;
// flushing = false;
// seen_callbacks.clear();
// }
export function flush() {
if (flushing) return;
flushing = true;
do {
// first, call beforeUpdate functions
// and update components
for (let i = 0; i < dirty_components.length; i += 1) {
const component = dirty_components[i];
set_current_component(component);
// update components + beforeUpdate
for (let i = 0, component; i < dirty_components.length; i++) {
set_current_component((component = dirty_components[i]));
update(component.$$);
}
dirty_components.length = 0;
while (binding_callbacks.length) binding_callbacks.pop()();
// then, once components are updated, call
// afterUpdate functions. This may cause
// subsequent updates...
for (let i = 0; i < render_callbacks.length; i += 1) {
const callback = render_callbacks[i];
if (!seen_callbacks.has(callback)) {
// ...so guard against infinite loops
seen_callbacks.add(callback);
callback();
}
// update bindings
for (let i = 0; i < binding_callbacks.length; i++) {
binding_callbacks[i]();
}
binding_callbacks.length = 0;
// afterUpdate
for (let i = 0, callback; i < render_callbacks.length; i++) {
if (seen_callbacks.has((callback = render_callbacks[i]))) continue;
seen_callbacks.add(callback);
callback();
}
render_callbacks.length = 0;
} while (dirty_components.length);
while (flush_callbacks.length) {
flush_callbacks.pop()();
for (let i = 0; i < flush_callbacks.length; i++) {
flush_callbacks[i]();
}
flush_callbacks.length = 0;
update_scheduled = false;
flushing = false;
seen_callbacks.clear();

@ -1,5 +1,4 @@
import { element } from './dom';
import { next_frame } from './loop';
const svelte_rule = `__svelte_`;

@ -4,7 +4,7 @@ import { raf_timeout, loopThen } from './loop';
import { generate_rule } from './style_manager';
import { custom_event } from './dom';
import { TransitionConfig } from '../transition';
import { add_render_callback } from './scheduler';
import { add_render_callback, add_flush_callback } from './scheduler';
function startStopDispatcher(node: Element, direction: boolean) {
add_render_callback(() => node.dispatchEvent(custom_event(`${direction ? 'intro' : 'outro'}start`)));
@ -37,6 +37,7 @@ export function transition_out(block, local?: 0 | 1, detach?: 0 | 1, callback?:
if (!block || !block.o || outroing.has(block)) return;
outroing.add(block);
outros.c.push(() => {
if (!outroing.has(block)) return;
outroing.delete(block);
if (!callback) return;
if (detach) block.d(1);
@ -95,7 +96,8 @@ export function run_transition(
if (reset_reverse === 2) return run_transition(node, fn, !is_intro, params, start_time);
else if (!~reversed_from) running_bidi.delete(node);
}
if (is_function(config)) add_render_callback(() => start((config = config())));
// @ts-ignore
if (is_function(config)) add_flush_callback(() => start((config = config())));
else start(config);
return stop;
}

Loading…
Cancel
Save