fromEventPattern.js 680 B

1234567891011121314
  1. import { Observable } from '../Observable';
  2. import { isFunction } from '../util/isFunction';
  3. import { mapOneOrManyArgs } from '../util/mapOneOrManyArgs';
  4. export function fromEventPattern(addHandler, removeHandler, resultSelector) {
  5. if (resultSelector) {
  6. return fromEventPattern(addHandler, removeHandler).pipe(mapOneOrManyArgs(resultSelector));
  7. }
  8. return new Observable((subscriber) => {
  9. const handler = (...e) => subscriber.next(e.length === 1 ? e[0] : e);
  10. const retValue = addHandler(handler);
  11. return isFunction(removeHandler) ? () => removeHandler(handler, retValue) : undefined;
  12. });
  13. }
  14. //# sourceMappingURL=fromEventPattern.js.map