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.

scan.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */
  2. import * as tslib_1 from "tslib";
  3. import { Subscriber } from '../Subscriber';
  4. export function scan(accumulator, seed) {
  5. var hasSeed = false;
  6. if (arguments.length >= 2) {
  7. hasSeed = true;
  8. }
  9. return function scanOperatorFunction(source) {
  10. return source.lift(new ScanOperator(accumulator, seed, hasSeed));
  11. };
  12. }
  13. var ScanOperator = /*@__PURE__*/ (function () {
  14. function ScanOperator(accumulator, seed, hasSeed) {
  15. if (hasSeed === void 0) {
  16. hasSeed = false;
  17. }
  18. this.accumulator = accumulator;
  19. this.seed = seed;
  20. this.hasSeed = hasSeed;
  21. }
  22. ScanOperator.prototype.call = function (subscriber, source) {
  23. return source.subscribe(new ScanSubscriber(subscriber, this.accumulator, this.seed, this.hasSeed));
  24. };
  25. return ScanOperator;
  26. }());
  27. var ScanSubscriber = /*@__PURE__*/ (function (_super) {
  28. tslib_1.__extends(ScanSubscriber, _super);
  29. function ScanSubscriber(destination, accumulator, _seed, hasSeed) {
  30. var _this = _super.call(this, destination) || this;
  31. _this.accumulator = accumulator;
  32. _this._seed = _seed;
  33. _this.hasSeed = hasSeed;
  34. _this.index = 0;
  35. return _this;
  36. }
  37. Object.defineProperty(ScanSubscriber.prototype, "seed", {
  38. get: function () {
  39. return this._seed;
  40. },
  41. set: function (value) {
  42. this.hasSeed = true;
  43. this._seed = value;
  44. },
  45. enumerable: true,
  46. configurable: true
  47. });
  48. ScanSubscriber.prototype._next = function (value) {
  49. if (!this.hasSeed) {
  50. this.seed = value;
  51. this.destination.next(value);
  52. }
  53. else {
  54. return this._tryNext(value);
  55. }
  56. };
  57. ScanSubscriber.prototype._tryNext = function (value) {
  58. var index = this.index++;
  59. var result;
  60. try {
  61. result = this.accumulator(this.seed, value, index);
  62. }
  63. catch (err) {
  64. this.destination.error(err);
  65. }
  66. this.seed = result;
  67. this.destination.next(result);
  68. };
  69. return ScanSubscriber;
  70. }(Subscriber));
  71. //# sourceMappingURL=scan.js.map