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.

switchMap.js 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /** PURE_IMPORTS_START tslib,_OuterSubscriber,_InnerSubscriber,_util_subscribeToResult,_map,_observable_from PURE_IMPORTS_END */
  2. import * as tslib_1 from "tslib";
  3. import { OuterSubscriber } from '../OuterSubscriber';
  4. import { InnerSubscriber } from '../InnerSubscriber';
  5. import { subscribeToResult } from '../util/subscribeToResult';
  6. import { map } from './map';
  7. import { from } from '../observable/from';
  8. export function switchMap(project, resultSelector) {
  9. if (typeof resultSelector === 'function') {
  10. return function (source) { return source.pipe(switchMap(function (a, i) { return from(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); })); };
  11. }
  12. return function (source) { return source.lift(new SwitchMapOperator(project)); };
  13. }
  14. var SwitchMapOperator = /*@__PURE__*/ (function () {
  15. function SwitchMapOperator(project) {
  16. this.project = project;
  17. }
  18. SwitchMapOperator.prototype.call = function (subscriber, source) {
  19. return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));
  20. };
  21. return SwitchMapOperator;
  22. }());
  23. var SwitchMapSubscriber = /*@__PURE__*/ (function (_super) {
  24. tslib_1.__extends(SwitchMapSubscriber, _super);
  25. function SwitchMapSubscriber(destination, project) {
  26. var _this = _super.call(this, destination) || this;
  27. _this.project = project;
  28. _this.index = 0;
  29. return _this;
  30. }
  31. SwitchMapSubscriber.prototype._next = function (value) {
  32. var result;
  33. var index = this.index++;
  34. try {
  35. result = this.project(value, index);
  36. }
  37. catch (error) {
  38. this.destination.error(error);
  39. return;
  40. }
  41. this._innerSub(result, value, index);
  42. };
  43. SwitchMapSubscriber.prototype._innerSub = function (result, value, index) {
  44. var innerSubscription = this.innerSubscription;
  45. if (innerSubscription) {
  46. innerSubscription.unsubscribe();
  47. }
  48. var innerSubscriber = new InnerSubscriber(this, undefined, undefined);
  49. var destination = this.destination;
  50. destination.add(innerSubscriber);
  51. this.innerSubscription = subscribeToResult(this, result, value, index, innerSubscriber);
  52. };
  53. SwitchMapSubscriber.prototype._complete = function () {
  54. var innerSubscription = this.innerSubscription;
  55. if (!innerSubscription || innerSubscription.closed) {
  56. _super.prototype._complete.call(this);
  57. }
  58. this.unsubscribe();
  59. };
  60. SwitchMapSubscriber.prototype._unsubscribe = function () {
  61. this.innerSubscription = null;
  62. };
  63. SwitchMapSubscriber.prototype.notifyComplete = function (innerSub) {
  64. var destination = this.destination;
  65. destination.remove(innerSub);
  66. this.innerSubscription = null;
  67. if (this.isStopped) {
  68. _super.prototype._complete.call(this);
  69. }
  70. };
  71. SwitchMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  72. this.destination.next(innerValue);
  73. };
  74. return SwitchMapSubscriber;
  75. }(OuterSubscriber));
  76. //# sourceMappingURL=switchMap.js.map