Skip to content

Polyfill for the getEventListeners method available in dev tools. Includes a) extended event listener options 'first', 'last' and 'unstoppable', b) a patch to scope calls to 'stopPropagation()'.

orstavik/getEventListeners

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

getEventListeners (polyfill)

Polyfill for the getEventListeners method available in dev tools.

Includes a) extended event listener options such as 'first', 'last' and 'unstoppable' and b) a patch that will scope calls to 'stopPropagation()' to only apply to other event listeners under the same propagation root (ie. under the same ShadowRoot/window). These additions are separated in different modules.

  1. WhatIs EventTarget
  2. WhatIs EquivalentEventListener
  3. Why ExtendEventTarget
  4. Pattern EventTargetRegistry
  5. Pattern HasAndGetEventListeners
  6. WhatIs onclickEtc
  7. Pattern OnceEventListenerOption
  8. Pattern FirstEventListener
  9. Pattern EventListenerPriority
  10. Pattern Event IsStopped
  11. Pattern UnstoppableEventListeners
  12. Pattern LastEventListenerOption
  13. Pattern ScopedStopProp
  14. Pattern GuaranteedBubbleListener
  15. Pattern ImmediateOnlyEventListenerOption

todo

x. make a chapter about the getEventListeners() method in Chrome dev tools. y. we need a discussion about the safety of the getEventListeners() method.

  • functions can be retrieved from the dom elements. this means that there source can be printed. to avoid that, wrap them inside anoter function that calls them, or bind them.
  • hide the access to the getEventListeners method, do not make it available via the window object for example, but keep its reference locked inside your framework js files.

how to use it

1. Simple getEventListener(eventTarget) polyfill

The simple getEventListener(eventTarget) supports the native once event listener option. The ES6 import returns an addEventTargetRegistry() function that should be run before any event listeners are added to the DOM.

import {addEventTargetRegistry} from "https://cdn.jsdelivr.net/gh/orstavik/getEventListeners@1.0.1/src/getEventListeners_once.js";

window.getEventListeners = addEventTargetRegistry();

2. last, first, unstoppable, scoped stopPropagation() and getEventListener(eventTarget) polyfill

To enable full development of web components that act like native web components you MUST have something like this.

import {addGetEventListeners_allOptions} from "https://cdn.jsdelivr.net/gh/orstavik/getEventListeners@1.1.2/src/getEventListeners_allOptions.js";

const {getEventListeners, isStopped} = addGetEventListeners_allOptions();

About

Polyfill for the getEventListeners method available in dev tools. Includes a) extended event listener options 'first', 'last' and 'unstoppable', b) a patch to scope calls to 'stopPropagation()'.

Resources

Stars

Watchers

Forks

Packages

No packages published