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

fromEventPattern.js 1.3KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var Observable_1 = require("../Observable");
  4. var isArray_1 = require("../util/isArray");
  5. var isFunction_1 = require("../util/isFunction");
  6. var map_1 = require("../operators/map");
  7. function fromEventPattern(addHandler, removeHandler, resultSelector) {
  8. if (resultSelector) {
  9. return fromEventPattern(addHandler, removeHandler).pipe(map_1.map(function (args) { return isArray_1.isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
  10. }
  11. return new Observable_1.Observable(function (subscriber) {
  12. var handler = function () {
  13. var e = [];
  14. for (var _i = 0; _i < arguments.length; _i++) {
  15. e[_i] = arguments[_i];
  16. }
  17. return subscriber.next(e.length === 1 ? e[0] : e);
  18. };
  19. var retValue;
  20. try {
  21. retValue = addHandler(handler);
  22. }
  23. catch (err) {
  24. subscriber.error(err);
  25. return undefined;
  26. }
  27. if (!isFunction_1.isFunction(removeHandler)) {
  28. return undefined;
  29. }
  30. return function () { return removeHandler(handler, retValue); };
  31. });
  32. }
  33. exports.fromEventPattern = fromEventPattern;
  34. //# sourceMappingURL=fromEventPattern.js.map