rimmel
Version:
A Stream-Oriented UI library for the Rx.Observable Universe
36 lines (33 loc) • 1.55 kB
JavaScript
import { isObservature } from './observature.js';
import { USE_DOM_OBSERVABLES } from '../constants.js';
import { toListener } from '../utils/to-listener.js';
const isEventListenerObject = (l) => !!l?.handleEvent;
const addListener = (node, eventName, listener, options) => {
// We also force-add an event listener if we're inside a ShadowRoot (do we really need to?), as events inside web components don't seem to fire otherwise
if (USE_DOM_OBSERVABLES && node.when) {
// Explicitly excluding the isEventListenerObject as Domenic doesn't want .when() to support it
if (!isEventListenerObject(listener)) {
const source = node.when(eventName, options);
if (isObservature(listener)) {
listener.addSource(source);
}
else {
// TODO: Add AbortController
source.subscribe(listener);
}
}
}
else {
node.addEventListener(eventName, toListener(listener), options);
// #REF49993849837451
// const listenerRef = [eventName, sourceBindingConfiguration.listener, sourceBindingConfiguration.options];
// node.addEventListener(...listenerRef);
// listeners.get(node)?.push?.(listenerRef) ?? listeners.set(node, [listenerRef]);
}
if (/^(?:rml:)?mount/.test(eventName)) {
// Will this need to bubble up? (probably no)
setTimeout(() => node.dispatchEvent(new Event(eventName)));
}
};
export { addListener };
//# sourceMappingURL=addListener.js.map