Skip to content

Commit

Permalink
updated ready fn
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed May 22, 2024
1 parent 9e35dd4 commit 0af3982
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions packages/clients/walkerjs/src/lib/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ export const Trigger: { [key: string]: Walker.Trigger } = {
Wait: 'wait',
} as const;

export function ready(
run: (instance: WebClient.Instance) => void,
instance: WebClient.Instance,
) {
const fn = () => {
run(instance);
export function ready<T extends (...args: never[]) => R, R>(
fn: T,
...args: Parameters<T>
): void {
const readyFn = () => {
fn(...args);
};

if (document.readyState !== 'loading') {
fn();
readyFn();
} else {
document.addEventListener('DOMContentLoaded', fn);
document.addEventListener('DOMContentLoaded', readyFn);
return;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/core/useHooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Hooks } from '@elbwalker/types';

export function useHooks<P extends any[], R>(
export function useHooks<P extends unknown[], R>(
fn: (...args: P) => R,
name: string,
hooks: Hooks.Functions,
Expand Down

0 comments on commit 0af3982

Please sign in to comment.