Skip to content

Commit

Permalink
Fix name support in debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrHoroshih committed Nov 18, 2023
1 parent 53072cf commit 76026df
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/debounce/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,33 @@ import {
attach,
merge,
UnitTargetable,
EventAsReturnType
EventAsReturnType,
} from 'effector';

export function debounce<T>(_: {
source: Unit<T>;
timeout: number | Store<number>;
name?: string;
}): EventAsReturnType<T>;
export function debounce<
T,
Target extends
| UnitTargetable<T>
| UnitTargetable<void>,
Target extends UnitTargetable<T> | UnitTargetable<void>,
>(_: {
source: Unit<T>;
timeout: number | Store<number>;
target: Target;
name?: string;
}): Target;
export function debounce<T>({
source,
timeout,
target,
name,
}: {
source: Unit<T>;
timeout?: number | Store<number>;
target?: UnitTargetable<T> | Unit<T>
target?: UnitTargetable<T> | Unit<T>;
name?: string;
}): typeof target extends undefined ? EventAsReturnType<T> : typeof target {
if (!is.unit(source)) throw new TypeError('source must be unit from effector');

Expand Down Expand Up @@ -69,7 +71,7 @@ export function debounce<T>({
});
});
const timerFx = attach({
name: `debounce(${(source as any)?.shortName || source.kind}) effect`,
name: name || `debounce(${(source as any)?.shortName || source.kind}) effect`,
source: {
timeoutId: $timeoutId,
rejectPromise: $rejecter,
Expand Down

0 comments on commit 76026df

Please sign in to comment.