wishthis/node_modules/rxjs/dist/esm/internal/observable/fromEventPattern.js

14 lines
680 B
JavaScript
Raw Normal View History

2022-06-08 10:36:39 +00:00
import { Observable } from '../Observable';
import { isFunction } from '../util/isFunction';
import { mapOneOrManyArgs } from '../util/mapOneOrManyArgs';
export function fromEventPattern(addHandler, removeHandler, resultSelector) {
if (resultSelector) {
return fromEventPattern(addHandler, removeHandler).pipe(mapOneOrManyArgs(resultSelector));
}
return new Observable((subscriber) => {
const handler = (...e) => subscriber.next(e.length === 1 ? e[0] : e);
const retValue = addHandler(handler);
return isFunction(removeHandler) ? () => removeHandler(handler, retValue) : undefined;
});
}
//# sourceMappingURL=fromEventPattern.js.map