From 4846efcdaec39cfe25b6108d640fe377acbb8db2 Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 30 Sep 2024 15:22:24 +0100 Subject: [PATCH] Change typing in some methods --- integration/custom/test/integration.spec.ts | 4 ++-- src/combine-events/index.ts | 10 +++++----- src/debug/index.ts | 4 ++-- src/once/index.ts | 4 ++-- src/snapshot/index.ts | 4 ++-- src/split-map/index.ts | 10 +++++----- src/throttle/index.ts | 6 +++--- test-library.d.ts | 6 +++--- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/integration/custom/test/integration.spec.ts b/integration/custom/test/integration.spec.ts index 642e32df..8f43a76d 100644 --- a/integration/custom/test/integration.spec.ts +++ b/integration/custom/test/integration.spec.ts @@ -1,4 +1,4 @@ -import { createEffect, Event } from 'effector'; +import { createEffect, EventCallable } from 'effector'; import { status } from '@effector/patronum/status'; import { pending } from '@effector/patronum/macro'; @@ -41,7 +41,7 @@ test('pending macro works as expected', () => { expect($pending.sid).toMatchInlineSnapshot(`"-hszfx7|a4upb3"`); }); -function waitFor(unit: Event) { +function waitFor(unit: EventCallable) { return new Promise((resolve) => { const unsubscribe = unit.watch((payload) => { resolve(payload); diff --git a/src/combine-events/index.ts b/src/combine-events/index.ts index 273d5d40..670a11b8 100644 --- a/src/combine-events/index.ts +++ b/src/combine-events/index.ts @@ -2,7 +2,7 @@ import { createEvent, createStore, Effect, - Event, + EventCallable, EventAsReturnType, is, sample, @@ -16,17 +16,17 @@ type Tuple = [T] | T[]; type Shape = Record | Tuple; type Events = { - [Key in keyof Result]: Event; + [Key in keyof Result]: EventCallable; }; type ReturnTarget = Target extends Store ? S extends Result ? Store : Store - : Target extends Event + : Target extends EventCallable ? P extends Result - ? Event

- : Event + ? EventCallable

+ : EventCallable : Target extends Effect ? P extends Result ? Effect diff --git a/src/debug/index.ts b/src/debug/index.ts index b0adcbfa..68c0fc8c 100644 --- a/src/debug/index.ts +++ b/src/debug/index.ts @@ -2,7 +2,7 @@ import { Stack, Node, Effect, - Event, + EventCallable, is, Store, Unit, @@ -120,7 +120,7 @@ function watchDomain(domain: Domain, config: Config) { } function watchUnit( - unit: Store | Event | Effect, + unit: Store | EventCallable | Effect, config: Config, ) { if (is.store(unit)) { diff --git a/src/once/index.ts b/src/once/index.ts index 4a70863d..7c23376b 100644 --- a/src/once/index.ts +++ b/src/once/index.ts @@ -1,6 +1,6 @@ import { Unit, - Event, + EventCallable, EventAsReturnType, is, sample, @@ -28,7 +28,7 @@ export function once( const $canTrigger = createStore(true); - const trigger: Event = sample({ + const trigger: EventCallable = sample({ source, filter: $canTrigger, }); diff --git a/src/snapshot/index.ts b/src/snapshot/index.ts index 30b60ab7..435d9559 100644 --- a/src/snapshot/index.ts +++ b/src/snapshot/index.ts @@ -1,4 +1,4 @@ -import { Effect, Event, Store, StoreWritable, Unit, createStore, sample } from 'effector'; +import { Effect, EventCallable, Store, StoreWritable, Unit, createStore, sample } from 'effector'; type NoInfer = [T][T extends any ? 0 : never]; @@ -8,7 +8,7 @@ export function snapshot({ fn = (value: SourceType) => value as unknown as TargetType, }: { source: Store; - clock?: Event | Effect | Store; + clock?: EventCallable | Effect | Store; fn?(value: SourceType): TargetType; }): StoreWritable> { const defaultValue = fn(source.defaultState); diff --git a/src/split-map/index.ts b/src/split-map/index.ts index 32bf9818..1416d71f 100644 --- a/src/split-map/index.ts +++ b/src/split-map/index.ts @@ -1,4 +1,4 @@ -import { Event, is, Store, Unit } from 'effector'; +import { EventCallable, is, Store, Unit } from 'effector'; export function splitMap< S, @@ -11,12 +11,12 @@ export function splitMap< cases: Cases; }): { [K in keyof Cases]: Cases[K] extends (p: S) => infer R - ? Event> + ? EventCallable> : never; -} & { __: Event } { - const result: Record | Store> = {}; +} & { __: EventCallable } { + const result: Record | Store> = {}; - let current = is.store(source) ? source.updates : (source as Event); + let current = is.store(source) ? source.updates : (source as EventCallable); for (const key in cases) { if (key in cases) { diff --git a/src/throttle/index.ts b/src/throttle/index.ts index 042189b8..4f352e7a 100644 --- a/src/throttle/index.ts +++ b/src/throttle/index.ts @@ -2,7 +2,7 @@ import { createEffect, createEvent, createStore, - Event, + EventCallable, is, sample, Store, @@ -10,7 +10,7 @@ import { UnitTargetable, } from 'effector'; -type EventAsReturnType = any extends Payload ? Event : never; +type EventAsReturnType = any extends Payload ? EventCallable : never; export function throttle( source: Unit, @@ -47,7 +47,7 @@ export function throttle( const $timeout = toStoreNumber(timeout); const timerFx = createEffect({ - name: `throttle(${(source as Event).shortName || source.kind}) effect`, + name: `throttle(${(source as EventCallable).shortName || source.kind}) effect`, handler: (timeout) => new Promise((resolve) => setTimeout(resolve, timeout)), }); diff --git a/test-library.d.ts b/test-library.d.ts index 809ff251..120ffa79 100644 --- a/test-library.d.ts +++ b/test-library.d.ts @@ -1,4 +1,4 @@ -import { Unit, Event, Store, Effect } from 'effector'; +import { Unit, EventCallable, Store, Effect } from 'effector'; export function argumentHistory(fn: jest.Mock): Array; export function argumentsHistory(fn: jest.Mock): Array>; @@ -19,9 +19,9 @@ export function wait(ms: number): Promise; export function waitFor(unit: Unit): Promise; export function watch( - unit: Event | Store | Effect, + unit: EventCallable | Store | Effect, ): jest.Mock; export function monitor( - units: Array | Store | Effect>, + units: Array | Store | Effect>, ): () => Array<[string, any]>;