types.ts 1.0 KB

1234567891011121314151617181920212223242526272829
  1. //#SECTION selector exists
  2. export type OnSelectorOpts<TElem extends Element = HTMLElement> = SelectorOptsOne<TElem> | SelectorOptsAll<TElem>;
  3. type SelectorOptsOne<TElem extends Element> = SelectorOptsBase & {
  4. /** Whether to use `querySelectorAll()` instead - default is false */
  5. all?: false;
  6. /** Gets called whenever the selector was found in the DOM */
  7. listener: (element: TElem) => void;
  8. };
  9. type SelectorOptsAll<TElem extends Element> = SelectorOptsBase & {
  10. /** Whether to use `querySelectorAll()` instead - default is false */
  11. all: true;
  12. /** Gets called whenever the selector was found in the DOM */
  13. listener: (elements: NodeListOf<TElem>) => void;
  14. };
  15. type SelectorOptsBase = {
  16. /** Whether to call the listener continuously instead of once - default is false */
  17. continuous?: boolean;
  18. };
  19. //#SECTION fetch advanced
  20. export type FetchAdvancedOpts = RequestInit & Partial<{
  21. /** Timeout in milliseconds after which the fetch call will be canceled with an AbortController signal */
  22. timeout: number;
  23. }>;