spectrum-web-components icon indicating copy to clipboard operation
spectrum-web-components copied to clipboard

Review use of abortSignal in events listener patterns.

Open Westbrook opened this issue 4 years ago • 0 comments

Code of conduct

  • [X] I agree to follow this project's code of conduct.

Description of issue

Can https://github.com/whatwg/dom/issues/911 be leveraged along the lines of:

const ac = new AbortController();
let { signal } = ac;
parentElement.addEventListener(
    'pointerenter',
    this.openOverlay,
    { signal }
);
parentElement.addEventListener('focusin', this.openOverlay, { signal });
parentElement.addEventListener(
    'pointerleave',
    this.closeOverlay,
    { signal }
);
parentElement.addEventListener('focusout', this.closeOverlay, { signal });
ac.abort();

To simplify events being added/removed from elements imperatively.

Things to confirm:

  • does the abortController really work across multiple listeners?
  • does Safari support it broadly enough to allow in the library?
  • does it have undesired perf costs?
  • others?

Westbrook avatar Oct 21 '21 15:10 Westbrook