pull/4999/head
pushkine 5 years ago
parent 927c892955
commit ab09b33d19

@ -47,7 +47,7 @@ export const update_keyed_each = (
const insert = (block) => { const insert = (block) => {
transition_in(block, 1); transition_in(block, 1);
block.m(node, next, lookup.has(block.key)); block.m(node, next);
lookup.set(block.key, block); lookup.set(block.key, block);
next = block.first; next = block.first;
n--; n--;

@ -118,5 +118,40 @@ export const onEachFrame = (
}; };
/** tests only */ /** tests only */
export const clear_loops = () => export const clear_loops = () => {
void (next_frame.length = running_frame.length = timed_tasks.length = pending_insert_timed.length = n = i = j = +(running_timed = pending_inserts = false)); next_frame.length = running_frame.length = timed_tasks.length = pending_insert_timed.length = n = i = j = +(running_timed = pending_inserts = false);
tasks.clear();
};
/** legacy loop for svelte/motion */
export interface MotionTask { abort(): void; promise: Promise<void> }
type MotionTaskCallback = (now: number) => boolean | void;
type MotionTaskEntry = { c: MotionTaskCallback; f: () => void };
const tasks = new Set<MotionTaskEntry>();
function run_tasks(now: number) {
tasks.forEach(task => {
if (!task.c(now)) {
tasks.delete(task);
task.f();
}
});
if (tasks.size !== 0) raf(run_tasks);
}
export function motion_loop(callback: MotionTaskCallback): MotionTask {
let task: MotionTaskEntry;
if (tasks.size === 0) raf(run_tasks);
return {
promise: new Promise(fulfill => {
tasks.add(task = { c: callback, f: fulfill });
}),
abort() {
tasks.delete(task);
}
};
}

@ -1,5 +1,5 @@
import { Readable, writable } from 'svelte/store'; import { Readable, writable } from 'svelte/store';
import { loop, now, Task } from 'svelte/internal'; import { motion_loop as loop, now, MotionTask as Task } from 'svelte/internal';
import { is_date } from './utils'; import { is_date } from './utils';
interface TickContext<T> { interface TickContext<T> {

@ -1,5 +1,5 @@
import { Readable, writable } from 'svelte/store'; import { Readable, writable } from 'svelte/store';
import { assign, loop, now, Task } from 'svelte/internal'; import { assign, motion_loop as loop, now, MotionTask as Task } from 'svelte/internal';
import { linear } from 'svelte/easing'; import { linear } from 'svelte/easing';
import { is_date } from './utils'; import { is_date } from './utils';

Loading…
Cancel
Save