skipLast.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.skipLast = void 0;
  4. var identity_1 = require("../util/identity");
  5. var lift_1 = require("../util/lift");
  6. var OperatorSubscriber_1 = require("./OperatorSubscriber");
  7. function skipLast(skipCount) {
  8. return skipCount <= 0
  9. ?
  10. identity_1.identity
  11. : lift_1.operate(function (source, subscriber) {
  12. var ring = new Array(skipCount);
  13. var seen = 0;
  14. source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) {
  15. var valueIndex = seen++;
  16. if (valueIndex < skipCount) {
  17. ring[valueIndex] = value;
  18. }
  19. else {
  20. var index = valueIndex % skipCount;
  21. var oldValue = ring[index];
  22. ring[index] = value;
  23. subscriber.next(oldValue);
  24. }
  25. }));
  26. return function () {
  27. ring = null;
  28. };
  29. });
  30. }
  31. exports.skipLast = skipLast;
  32. //# sourceMappingURL=skipLast.js.map