This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from asigloo/bugfix/fix-vue-warns
fix: removed all warnings
- Loading branch information
Showing
12 changed files
with
89 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
export type FunctionArgs<Args extends any[] = any[], Return = void> = ( | ||
...args: Args | ||
) => Return; | ||
|
||
export interface FunctionWrapperOptions< | ||
Args extends any[] = any[], | ||
This = any | ||
> { | ||
fn: FunctionArgs<Args, This>; | ||
args: Args; | ||
thisArg: This; | ||
} | ||
|
||
export type EventFilter<Args extends any[] = any[], This = any> = ( | ||
invoke: () => void, | ||
options: FunctionWrapperOptions<Args, This>, | ||
) => void; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function createFilterWrapper<T extends FunctionArgs>( | ||
filter: EventFilter, | ||
fn: T, | ||
) { | ||
function wrapper(this: any, ...args: any[]) { | ||
filter(() => fn.apply(this, args), { fn, thisArg: this, args }); | ||
} | ||
|
||
return (wrapper as any) as T; | ||
} | ||
|
||
export const bypassFilter: EventFilter = invoke => { | ||
return invoke(); | ||
}; | ||
|
||
export function debounceFilter(ms: number): EventFilter { | ||
if (ms <= 0) return bypassFilter; | ||
|
||
let timer: ReturnType<typeof setTimeout> | undefined; | ||
|
||
const filter: EventFilter = invoke => { | ||
if (timer) clearTimeout(timer); | ||
|
||
timer = setTimeout(invoke, ms); | ||
}; | ||
|
||
return filter; | ||
} | ||
|
||
export function useDebounceFn<T extends FunctionArgs>(fn: T, ms = 200): T { | ||
return createFilterWrapper(debounceFilter(ms), fn); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters