diff --git a/src/runtime/internal/lifecycle.ts b/src/runtime/internal/lifecycle.ts index 7a6fac2c69..e75bbdc501 100644 --- a/src/runtime/internal/lifecycle.ts +++ b/src/runtime/internal/lifecycle.ts @@ -140,7 +140,7 @@ export function getAllContexts = Map>(): T { * https://svelte.dev/docs#run-time-svelte-hascontext */ export function hasContext(key): boolean { - return get_current_component().$$.context.has(key); + return get_current_component().$$.context.has(key); } // TODO figure out if we still want to support diff --git a/src/runtime/internal/utils.ts b/src/runtime/internal/utils.ts index 79c3ccba42..bc2f2f6e7a 100644 --- a/src/runtime/internal/utils.ts +++ b/src/runtime/internal/utils.ts @@ -1,16 +1,16 @@ -import { Readable, Subscriber, Invalidator, Writable } from 'svelte/store'; +import { Readable, Subscriber, Writable } from 'svelte/store'; import { SvelteComponent } from '../index.js'; -export function noop() { } +type TODO = T -export function identity(x: T): T { - return x; -} +export function noop() {} + +export const identity = (x: T): T => x; -export function assign(target: T, source: S): T & S { +export function assign(tar: T, src: S): T & S { // @ts-ignore - for (const k in source) target[k] = source[k]; - return target as T & S; + for (const k in src) tar[k] = src[k]; + return tar as T & S; } // Adapted from https://github.com/then/is-promise/blob/master/index.js @@ -69,11 +69,13 @@ export function validate_store>(store: S, name: stri } } -export function subscribe>(store: S, run: Subscriber, invalidate?: Invalidator) { +export function subscribe>(store: S, ...callbacks: Array>) { if (store == null) { 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>(store: S): T { @@ -170,7 +172,7 @@ export function compute_slots>(slots: S) { export function once(fn: Function) { let ran = false; - return function (this: any, ...args: unknown[]) { + return function(this: any, ...args: unknown[]) { if (ran) return; ran = true; fn.call(this, ...args); diff --git a/src/runtime/store/index.ts b/src/runtime/store/index.ts index 30f5faf27d..16832f10d9 100644 --- a/src/runtime/store/index.ts +++ b/src/runtime/store/index.ts @@ -10,7 +10,7 @@ export type Unsubscriber = () => void; export type Updater = (value: T) => T; /** Cleanup logic callback. */ -export type Invalidator = (value?: T) => void; +type Invalidator = (value?: T) => void; /** Start and stop notification callbacks. */ export type StartStopNotifier = (set: Subscriber) => Unsubscriber | void;