Skip to content
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

Change typing in some methods #338

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 integration/custom/test/integration.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -41,7 +41,7 @@ test('pending macro works as expected', () => {
expect($pending.sid).toMatchInlineSnapshot(`"-hszfx7|a4upb3"`);
});

function waitFor<T>(unit: Event<T>) {
function waitFor<T>(unit: EventCallable<T>) {
return new Promise<T>((resolve) => {
const unsubscribe = unit.watch((payload) => {
resolve(payload);
Expand Down
10 changes: 5 additions & 5 deletions src/combine-events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
createEvent,
createStore,
Effect,
Event,
EventCallable,
EventAsReturnType,
is,
sample,
Expand All @@ -16,17 +16,17 @@ type Tuple<T = unknown> = [T] | T[];
type Shape = Record<string, unknown> | Tuple;

type Events<Result> = {
[Key in keyof Result]: Event<Result[Key]>;
[Key in keyof Result]: EventCallable<Result[Key]>;
};

type ReturnTarget<Result, Target> = Target extends Store<infer S>
? S extends Result
? Store<S>
: Store<Result>
: Target extends Event<infer P>
: Target extends EventCallable<infer P>
? P extends Result
? Event<P>
: Event<Result>
? EventCallable<P>
: EventCallable<Result>
: Target extends Effect<infer P, infer D, infer F>
? P extends Result
? Effect<P, D, F>
Expand Down
4 changes: 2 additions & 2 deletions src/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
Stack,
Node,
Effect,
Event,
EventCallable,
is,
Store,
Unit,
Expand Down Expand Up @@ -120,7 +120,7 @@ function watchDomain(domain: Domain, config: Config) {
}

function watchUnit(
unit: Store<any> | Event<any> | Effect<any, any, any>,
unit: Store<any> | EventCallable<any> | Effect<any, any, any>,
config: Config,
) {
if (is.store(unit)) {
Expand Down
4 changes: 2 additions & 2 deletions src/once/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
Unit,
Event,
EventCallable,
EventAsReturnType,
is,
sample,
Expand Down Expand Up @@ -28,7 +28,7 @@ export function once<T>(

const $canTrigger = createStore<boolean>(true);

const trigger: Event<T> = sample({
const trigger: EventCallable<T> = sample({
source,
filter: $canTrigger,
});
Expand Down
4 changes: 2 additions & 2 deletions src/snapshot/index.ts
Original file line number Diff line number Diff line change
@@ -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][T extends any ? 0 : never];

Expand All @@ -8,7 +8,7 @@ export function snapshot<SourceType, TargetType = SourceType>({
fn = (value: SourceType) => value as unknown as TargetType,
}: {
source: Store<SourceType>;
clock?: Event<any> | Effect<any, any, any> | Store<any>;
clock?: EventCallable<any> | Effect<any, any, any> | Store<any>;
fn?(value: SourceType): TargetType;
}): StoreWritable<NoInfer<TargetType>> {
const defaultValue = fn(source.defaultState);
Expand Down
10 changes: 5 additions & 5 deletions src/split-map/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Event, is, Store, Unit } from 'effector';
import { EventCallable, is, Store, Unit } from 'effector';

export function splitMap<
S,
Expand All @@ -11,12 +11,12 @@ export function splitMap<
cases: Cases;
}): {
[K in keyof Cases]: Cases[K] extends (p: S) => infer R
? Event<Exclude<R, undefined>>
? EventCallable<Exclude<R, undefined>>
: never;
} & { __: Event<S> } {
const result: Record<string, Event<any> | Store<any>> = {};
} & { __: EventCallable<S> } {
const result: Record<string, EventCallable<any> | Store<any>> = {};

let current = is.store(source) ? source.updates : (source as Event<S>);
let current = is.store(source) ? source.updates : (source as EventCallable<S>);

for (const key in cases) {
if (key in cases) {
Expand Down
6 changes: 3 additions & 3 deletions src/throttle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import {
createEffect,
createEvent,
createStore,
Event,
EventCallable,
is,
sample,
Store,
Unit,
UnitTargetable,
} from 'effector';

type EventAsReturnType<Payload> = any extends Payload ? Event<Payload> : never;
type EventAsReturnType<Payload> = any extends Payload ? EventCallable<Payload> : never;

export function throttle<T>(
source: Unit<T>,
Expand Down Expand Up @@ -47,7 +47,7 @@ export function throttle<T>(
const $timeout = toStoreNumber(timeout);

const timerFx = createEffect<number, void>({
name: `throttle(${(source as Event<T>).shortName || source.kind}) effect`,
name: `throttle(${(source as EventCallable<T>).shortName || source.kind}) effect`,
handler: (timeout) => new Promise((resolve) => setTimeout(resolve, timeout)),
});

Expand Down
6 changes: 3 additions & 3 deletions test-library.d.ts
Original file line number Diff line number Diff line change
@@ -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<unknown>;
export function argumentsHistory(fn: jest.Mock): Array<Array<unknown>>;
Expand All @@ -19,9 +19,9 @@ export function wait(ms: number): Promise<void>;
export function waitFor<T>(unit: Unit<T>): Promise<T>;

export function watch<T>(
unit: Event<T> | Store<T> | Effect<T, any, any>,
unit: EventCallable<T> | Store<T> | Effect<T, any, any>,
): jest.Mock<T, [T]>;

export function monitor(
units: Array<Event<any> | Store<any> | Effect<any, any, any>>,
units: Array<EventCallable<any> | Store<any> | Effect<any, any, any>>,
): () => Array<[string, any]>;
Loading