add global `resolved_promise`

pull/7703/head
Ivan Hofer 4 years ago
parent 9e51c8612d
commit 0c472c00c7

@ -0,0 +1 @@
export const resolved_promise = Promise.resolve();

@ -1,5 +1,6 @@
import { run_all } from './utils';
import { current_component, set_current_component } from './lifecycle';
import { resolved_promise } from './constants';
export const dirty_components = [];
export const intros = { enabled: false };
@ -8,7 +9,6 @@ export const binding_callbacks = [];
const render_callbacks = [];
const flush_callbacks = [];
const resolved_promise = Promise.resolve();
let update_scheduled = false;
export function schedule_update() {

@ -6,6 +6,7 @@ import { custom_event } from './dom';
import { add_render_callback } from './scheduler';
import { TransitionConfig } from '../transition';
import { Fragment } from './Component';
import { resolved_promise } from './constants';
let promise: Promise<void> | null;
type INTRO = 1;
@ -27,7 +28,7 @@ interface Outro {
function wait() {
if (!promise) {
promise = Promise.resolve();
promise = resolved_promise;
promise.then(() => {
promise = null;
});

@ -1,6 +1,7 @@
import { Readable, writable } from 'svelte/store';
import { loop, now, Task } from 'svelte/internal';
import { is_date } from './utils';
import { resolved_promise } from 'svelte/internal/constants';
interface TickContext<T> {
inv_mass: number;
@ -89,7 +90,7 @@ export function spring<T=any>(value?: T, opts: SpringOpts = {}): Spring<T> {
last_time = now();
last_value = new_value;
store.set(value = target_value);
return Promise.resolve();
return resolved_promise;
} else if (opts.soft) {
const rate = opts.soft === true ? .5 : +opts.soft;
inv_mass_recovery_rate = 1 / (rate * 60);

@ -2,6 +2,7 @@ import { Readable, writable } from 'svelte/store';
import { assign, loop, now, Task } from 'svelte/internal';
import { linear } from 'svelte/easing';
import { is_date } from './utils';
import { resolved_promise } from 'svelte/internal/constants';
function get_interpolator(a, b) {
if (a === b || a !== a) return () => a;
@ -78,7 +79,7 @@ export function tweened<T>(value?: T, defaults: Options<T> = {}): Tweened<T> {
function set(new_value: T, opts?: Options<T>) {
if (value == null) {
store.set(value = new_value);
return Promise.resolve();
return resolved_promise;
}
target_value = new_value;
@ -100,7 +101,7 @@ export function tweened<T>(value?: T, defaults: Options<T> = {}): Tweened<T> {
}
store.set(value = target_value);
return Promise.resolve();
return resolved_promise;
}
const start = now() + delay;

Loading…
Cancel
Save