Skip to content

Commit 12579d4

Browse files
authored
chore: remove unnecessary Invalidator type (#12354)
* chore: fix Invalidator type * regenerate types * in fact you know what, this whole thing is overkill. get rid of it * oops
1 parent 2789a3c commit 12579d4

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

packages/svelte/src/store/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @import { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable } from './public' */
2-
/** @import { Invalidator, Stores, StoresValues, SubscribeInvalidateTuple } from './private' */
2+
/** @import { Stores, StoresValues, SubscribeInvalidateTuple } from './private' */
33
import { noop, run_all } from '../internal/shared/utils.js';
44
import { safe_not_equal } from '../internal/client/reactivity/equality.js';
55
import { subscribe_to_store } from './utils.js';
@@ -74,7 +74,7 @@ export function writable(value, start = noop) {
7474

7575
/**
7676
* @param {Subscriber<T>} run
77-
* @param {Invalidator<T>} [invalidate]
77+
* @param {() => void} [invalidate]
7878
* @returns {Unsubscriber}
7979
*/
8080
function subscribe(run, invalidate = noop) {
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { Readable, Subscriber } from './public.js';
22

3-
/** Cleanup logic callback. */
4-
type Invalidator<T> = (value?: T) => void;
5-
63
/** Pair of subscriber and invalidator. */
7-
type SubscribeInvalidateTuple<T> = [Subscriber<T>, Invalidator<T>];
4+
type SubscribeInvalidateTuple<T> = [Subscriber<T>, () => void];
85

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

16-
export { Invalidator, SubscribeInvalidateTuple, Stores, StoresValues };
13+
export { SubscribeInvalidateTuple, Stores, StoresValues };

packages/svelte/src/store/public.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { Invalidator } from './private.js';
2-
31
/** Callback to inform of a value updates. */
42
type Subscriber<T> = (value: T) => void;
53

@@ -30,7 +28,7 @@ interface Readable<T> {
3028
* @param run subscription callback
3129
* @param invalidate cleanup callback
3230
*/
33-
subscribe(this: void, run: Subscriber<T>, invalidate?: Invalidator<T>): Unsubscriber;
31+
subscribe(this: void, run: Subscriber<T>, invalidate?: () => void): Unsubscriber;
3432
}
3533

3634
/** Writable interface for both updating and subscribing. */

packages/svelte/types/index.d.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,7 @@ declare module 'svelte/motion' {
20752075
* @param run subscription callback
20762076
* @param invalidate cleanup callback
20772077
*/
2078-
subscribe(this: void, run: Subscriber<T>, invalidate?: Invalidator<T>): Unsubscriber;
2078+
subscribe(this: void, run: Subscriber<T>, invalidate?: () => void): Unsubscriber;
20792079
}
20802080
interface SpringOpts {
20812081
stiffness?: number;
@@ -2096,8 +2096,6 @@ declare module 'svelte/motion' {
20962096
easing?: (t: number) => number;
20972097
interpolate?: (a: T, b: T) => (t: number) => T;
20982098
}
2099-
/** Cleanup logic callback. */
2100-
type Invalidator<T> = (value?: T) => void;
21012099
/**
21022100
* 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.
21032101
*
@@ -2221,7 +2219,7 @@ declare module 'svelte/store' {
22212219
* @param run subscription callback
22222220
* @param invalidate cleanup callback
22232221
*/
2224-
subscribe(this: void, run: Subscriber<T>, invalidate?: Invalidator<T>): Unsubscriber;
2222+
subscribe(this: void, run: Subscriber<T>, invalidate?: () => void): Unsubscriber;
22252223
}
22262224

22272225
/** Writable interface for both updating and subscribing. */
@@ -2238,15 +2236,6 @@ declare module 'svelte/store' {
22382236
*/
22392237
update(this: void, updater: Updater<T>): void;
22402238
}
2241-
/** Cleanup logic callback. */
2242-
type Invalidator<T> = (value?: T) => void;
2243-
2244-
/** One or more `Readable`s. */
2245-
type Stores = Readable<any> | [Readable<any>, ...Array<Readable<any>>] | Array<Readable<any>>;
2246-
2247-
/** One or more values from `Readable` stores. */
2248-
type StoresValues<T> =
2249-
T extends Readable<infer U> ? U : { [K in keyof T]: T[K] extends Readable<infer U> ? U : never };
22502239
/**
22512240
* Creates a `Readable` store that allows reading by subscription.
22522241
*
@@ -2288,6 +2277,12 @@ declare module 'svelte/store' {
22882277
* https://svelte.dev/docs/svelte-store#get
22892278
* */
22902279
export function get<T>(store: Readable<T>): T;
2280+
/** One or more `Readable`s. */
2281+
type Stores = Readable<any> | [Readable<any>, ...Array<Readable<any>>] | Array<Readable<any>>;
2282+
2283+
/** One or more values from `Readable` stores. */
2284+
type StoresValues<T> =
2285+
T extends Readable<infer U> ? U : { [K in keyof T]: T[K] extends Readable<infer U> ? U : never };
22912286

22922287
export { Subscriber, Unsubscriber, Updater, StartStopNotifier, Readable, Writable };
22932288
}

0 commit comments

Comments
 (0)