Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fromEventPattern.js 1.2KB

1234567891011121314151617181920212223242526272829303132
  1. /** PURE_IMPORTS_START _Observable,_util_isArray,_util_isFunction,_operators_map PURE_IMPORTS_END */
  2. import { Observable } from '../Observable';
  3. import { isArray } from '../util/isArray';
  4. import { isFunction } from '../util/isFunction';
  5. import { map } from '../operators/map';
  6. export function fromEventPattern(addHandler, removeHandler, resultSelector) {
  7. if (resultSelector) {
  8. return fromEventPattern(addHandler, removeHandler).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
  9. }
  10. return new Observable(function (subscriber) {
  11. var handler = function () {
  12. var e = [];
  13. for (var _i = 0; _i < arguments.length; _i++) {
  14. e[_i] = arguments[_i];
  15. }
  16. return subscriber.next(e.length === 1 ? e[0] : e);
  17. };
  18. var retValue;
  19. try {
  20. retValue = addHandler(handler);
  21. }
  22. catch (err) {
  23. subscriber.error(err);
  24. return undefined;
  25. }
  26. if (!isFunction(removeHandler)) {
  27. return undefined;
  28. }
  29. return function () { return removeHandler(handler, retValue); };
  30. });
  31. }
  32. //# sourceMappingURL=fromEventPattern.js.map