MCPcopy
hub / github.com/ampproject/amphtml / forwardEvents

Method forwardEvents

src/base-element.js:751–759  ·  view source on GitHub ↗

* Utility method that forwards the given list of non-bubbling events * from the given element to this element as custom events with the same name. * @param {string|!Array } events * @param {!Element} element * @public @final * @return {!UnlistenDef}

(events, element)

Source from the content-addressed store, hash-verified

749 * @return {!UnlistenDef}
750 */
751 forwardEvents(events, element) {
752 const unlisteners = (isArray(events) ? events : [events]).map((eventType) =>
753 listen(element, eventType, (event) => {
754 dispatchCustomEvent(this.element, eventType, getData(event) || {});
755 })
756 );
757
758 return () => unlisteners.forEach((unlisten) => unlisten());
759 }
760
761 /**
762 * Returns an optional placeholder element for this custom element.

Callers 2

installEventHandlers_Method · 0.80

Calls 6

listenFunction · 0.90
dispatchCustomEventFunction · 0.90
getDataFunction · 0.90
isArrayFunction · 0.85
unlistenFunction · 0.85
forEachMethod · 0.45

Tested by

no test coverage detected