UNPKG

896 BJavaScriptView Raw
1import { fromEventPattern } from './fromeventpattern';
2function isNodeEventEmitter(obj) {
3 return !!obj && typeof obj.addListener === 'function' && typeof obj.removeListener === 'function';
4}
5function isEventTarget(obj) {
6 return (!!obj &&
7 typeof obj.addEventListener === 'function' &&
8 typeof obj.removeEventListener === 'function');
9}
10export function fromEvent(obj, type, options) {
11 if (isEventTarget(obj)) {
12 const target = obj;
13 return fromEventPattern(h => target.addEventListener(type, h, options), h => target.removeEventListener(type, h, options));
14 }
15 else if (isNodeEventEmitter(obj)) {
16 const target = obj;
17 return fromEventPattern(h => target.addListener(type, h), h => target.removeListener(type, h));
18 }
19 else {
20 throw new TypeError('Unsupported event target');
21 }
22}
23
24//# sourceMappingURL=fromevent.mjs.map