|
|
|
@ -1,16 +1,16 @@
|
|
|
|
import { Readable, Subscriber, Invalidator, Writable } from 'svelte/store';
|
|
|
|
import { Readable, Subscriber, Writable } from 'svelte/store';
|
|
|
|
import { SvelteComponent } from '../index.js';
|
|
|
|
import { SvelteComponent } from '../index.js';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type TODO<T = any> = T
|
|
|
|
|
|
|
|
|
|
|
|
export function noop() {}
|
|
|
|
export function noop() {}
|
|
|
|
|
|
|
|
|
|
|
|
export function identity<T>(x: T): T {
|
|
|
|
export const identity = <T>(x: T): T => x;
|
|
|
|
return x;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function assign<T, S>(target: T, source: S): T & S {
|
|
|
|
export function assign<T, S>(tar: T, src: S): T & S {
|
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
for (const k in source) target[k] = source[k];
|
|
|
|
for (const k in src) tar[k] = src[k];
|
|
|
|
return target as T & S;
|
|
|
|
return tar as T & S;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Adapted from https://github.com/then/is-promise/blob/master/index.js
|
|
|
|
// Adapted from https://github.com/then/is-promise/blob/master/index.js
|
|
|
|
@ -69,11 +69,13 @@ export function validate_store<S extends Readable<unknown>>(store: S, name: stri
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function subscribe<T, S extends Readable<T>>(store: S, run: Subscriber<T>, invalidate?: Invalidator<T>) {
|
|
|
|
export function subscribe<T, S extends Readable<T>>(store: S, ...callbacks: Array<Subscriber<T>>) {
|
|
|
|
if (store == null) {
|
|
|
|
if (store == null) {
|
|
|
|
return noop;
|
|
|
|
return noop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return store.subscribe(run, invalidate);
|
|
|
|
// TODO: `store` does not accept an array of callbacks
|
|
|
|
|
|
|
|
const unsub: TODO = store.subscribe(...(callbacks as [TODO]));
|
|
|
|
|
|
|
|
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function get_store_value<T, S extends Readable<T>>(store: S): T {
|
|
|
|
export function get_store_value<T, S extends Readable<T>>(store: S): T {
|
|
|
|
|