onSelector.ts 887 B

123456789101112131415161718192021
  1. import { SelectorExistsOpts } from "./types";
  2. /**
  3. * Calls the `listener` as soon as the `selector` exists in the DOM.
  4. * Listeners are deleted when they are called once, unless `options.continuous` is set.
  5. * Multiple listeners with the same selector may be registered.
  6. * @template TElem The type of element that this selector will return - FIXME: listener inferring doesn't work when this generic is given
  7. */
  8. export function onSelector<TElem = HTMLElement, TOpts extends SelectorExistsOpts = SelectorExistsOpts>(
  9. options: TOpts,
  10. listener: (element: TOpts["all"] extends true ? (TElem extends HTMLElement ? NodeListOf<TElem> : TElem) : TElem) => void,
  11. ) {
  12. // TODO:
  13. void [options, listener];
  14. }
  15. /** Removes all listeners registered in `onSelector()` with a matching selector property */
  16. export function removeOnSelector(selector: string) {
  17. // TODO:
  18. void [selector];
  19. }