Skip to content

chore: remove unnecessary Invalidator type #12354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/svelte/src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @import { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable } from './public' */
/** @import { Invalidator, Stores, StoresValues, SubscribeInvalidateTuple } from './private' */
/** @import { Stores, StoresValues, SubscribeInvalidateTuple } from './private' */
import { noop, run_all } from '../internal/shared/utils.js';
import { safe_not_equal } from '../internal/client/reactivity/equality.js';
import { subscribe_to_store } from './utils.js';
Expand Down Expand Up @@ -74,7 +74,7 @@ export function writable(value, start = noop) {

/**
* @param {Subscriber<T>} run
* @param {Invalidator<T>} [invalidate]
* @param {() => void} [invalidate]
* @returns {Unsubscriber}
*/
function subscribe(run, invalidate = noop) {
Expand Down
7 changes: 2 additions & 5 deletions packages/svelte/src/store/private.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Readable, Subscriber } from './public.js';

/** Cleanup logic callback. */
type Invalidator<T> = (value?: T) => void;

/** Pair of subscriber and invalidator. */
type SubscribeInvalidateTuple<T> = [Subscriber<T>, Invalidator<T>];
type SubscribeInvalidateTuple<T> = [Subscriber<T>, () => void];

/** One or more `Readable`s. */
type Stores = Readable<any> | [Readable<any>, ...Array<Readable<any>>] | Array<Readable<any>>;
Expand All @@ -13,4 +10,4 @@ type Stores = Readable<any> | [Readable<any>, ...Array<Readable<any>>] | Array<R
type StoresValues<T> =
T extends Readable<infer U> ? U : { [K in keyof T]: T[K] extends Readable<infer U> ? U : never };

export { Invalidator, SubscribeInvalidateTuple, Stores, StoresValues };
export { SubscribeInvalidateTuple, Stores, StoresValues };
4 changes: 1 addition & 3 deletions packages/svelte/src/store/public.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Invalidator } from './private.js';

/** Callback to inform of a value updates. */
type Subscriber<T> = (value: T) => void;

Expand Down Expand Up @@ -30,7 +28,7 @@ interface Readable<T> {
* @param run subscription callback
* @param invalidate cleanup callback
*/
subscribe(this: void, run: Subscriber<T>, invalidate?: Invalidator<T>): Unsubscriber;
subscribe(this: void, run: Subscriber<T>, invalidate?: () => void): Unsubscriber;
}

/** Writable interface for both updating and subscribing. */
Expand Down
21 changes: 8 additions & 13 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2075,7 +2075,7 @@ declare module 'svelte/motion' {
* @param run subscription callback
* @param invalidate cleanup callback
*/
subscribe(this: void, run: Subscriber<T>, invalidate?: Invalidator<T>): Unsubscriber;
subscribe(this: void, run: Subscriber<T>, invalidate?: () => void): Unsubscriber;
}
interface SpringOpts {
stiffness?: number;
Expand All @@ -2096,8 +2096,6 @@ declare module 'svelte/motion' {
easing?: (t: number) => number;
interpolate?: (a: T, b: T) => (t: number) => T;
}
/** Cleanup logic callback. */
type Invalidator<T> = (value?: T) => void;
/**
* The spring function in Svelte creates a store whose value is animated, with a motion that simulates the behavior of a spring. This means when the value changes, instead of transitioning at a steady rate, it "bounces" like a spring would, depending on the physics parameters provided. This adds a level of realism to the transitions and can enhance the user experience.
*
Expand Down Expand Up @@ -2221,7 +2219,7 @@ declare module 'svelte/store' {
* @param run subscription callback
* @param invalidate cleanup callback
*/
subscribe(this: void, run: Subscriber<T>, invalidate?: Invalidator<T>): Unsubscriber;
subscribe(this: void, run: Subscriber<T>, invalidate?: () => void): Unsubscriber;
}

/** Writable interface for both updating and subscribing. */
Expand All @@ -2238,15 +2236,6 @@ declare module 'svelte/store' {
*/
update(this: void, updater: Updater<T>): void;
}
/** Cleanup logic callback. */
type Invalidator<T> = (value?: T) => void;

/** One or more `Readable`s. */
type Stores = Readable<any> | [Readable<any>, ...Array<Readable<any>>] | Array<Readable<any>>;

/** One or more values from `Readable` stores. */
type StoresValues<T> =
T extends Readable<infer U> ? U : { [K in keyof T]: T[K] extends Readable<infer U> ? U : never };
/**
* Creates a `Readable` store that allows reading by subscription.
*
Expand Down Expand Up @@ -2288,6 +2277,12 @@ declare module 'svelte/store' {
* https://svelte.dev/docs/svelte-store#get
* */
export function get<T>(store: Readable<T>): T;
/** One or more `Readable`s. */
type Stores = Readable<any> | [Readable<any>, ...Array<Readable<any>>] | Array<Readable<any>>;

/** One or more values from `Readable` stores. */
type StoresValues<T> =
T extends Readable<infer U> ? U : { [K in keyof T]: T[K] extends Readable<infer U> ? U : never };

export { Subscriber, Unsubscriber, Updater, StartStopNotifier, Readable, Writable };
}
Expand Down
Loading