Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

fromEventPattern.js 926B

12345678910111213141516171819202122232425
  1. import { Observable } from '../Observable';
  2. import { isArray } from '../util/isArray';
  3. import { isFunction } from '../util/isFunction';
  4. import { map } from '../operators/map';
  5. export function fromEventPattern(addHandler, removeHandler, resultSelector) {
  6. if (resultSelector) {
  7. return fromEventPattern(addHandler, removeHandler).pipe(map(args => isArray(args) ? resultSelector(...args) : resultSelector(args)));
  8. }
  9. return new Observable(subscriber => {
  10. const handler = (...e) => subscriber.next(e.length === 1 ? e[0] : e);
  11. let retValue;
  12. try {
  13. retValue = addHandler(handler);
  14. }
  15. catch (err) {
  16. subscriber.error(err);
  17. return undefined;
  18. }
  19. if (!isFunction(removeHandler)) {
  20. return undefined;
  21. }
  22. return () => removeHandler(handler, retValue);
  23. });
  24. }
  25. //# sourceMappingURL=fromEventPattern.js.map