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

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

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

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

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

Loading…
Cancel
Save