minor adjustment to readme
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / internal / operators / takeLast.js
1 "use strict";
2 var __extends = (this && this.__extends) || (function () {
3     var extendStatics = function (d, b) {
4         extendStatics = Object.setPrototypeOf ||
5             ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6             function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7         return extendStatics(d, b);
8     }
9     return function (d, b) {
10         extendStatics(d, b);
11         function __() { this.constructor = d; }
12         d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13     };
14 })();
15 Object.defineProperty(exports, "__esModule", { value: true });
16 var Subscriber_1 = require("../Subscriber");
17 var ArgumentOutOfRangeError_1 = require("../util/ArgumentOutOfRangeError");
18 var empty_1 = require("../observable/empty");
19 function takeLast(count) {
20     return function takeLastOperatorFunction(source) {
21         if (count === 0) {
22             return empty_1.empty();
23         }
24         else {
25             return source.lift(new TakeLastOperator(count));
26         }
27     };
28 }
29 exports.takeLast = takeLast;
30 var TakeLastOperator = (function () {
31     function TakeLastOperator(total) {
32         this.total = total;
33         if (this.total < 0) {
34             throw new ArgumentOutOfRangeError_1.ArgumentOutOfRangeError;
35         }
36     }
37     TakeLastOperator.prototype.call = function (subscriber, source) {
38         return source.subscribe(new TakeLastSubscriber(subscriber, this.total));
39     };
40     return TakeLastOperator;
41 }());
42 var TakeLastSubscriber = (function (_super) {
43     __extends(TakeLastSubscriber, _super);
44     function TakeLastSubscriber(destination, total) {
45         var _this = _super.call(this, destination) || this;
46         _this.total = total;
47         _this.ring = new Array();
48         _this.count = 0;
49         return _this;
50     }
51     TakeLastSubscriber.prototype._next = function (value) {
52         var ring = this.ring;
53         var total = this.total;
54         var count = this.count++;
55         if (ring.length < total) {
56             ring.push(value);
57         }
58         else {
59             var index = count % total;
60             ring[index] = value;
61         }
62     };
63     TakeLastSubscriber.prototype._complete = function () {
64         var destination = this.destination;
65         var count = this.count;
66         if (count > 0) {
67             var total = this.count >= this.total ? this.total : this.count;
68             var ring = this.ring;
69             for (var i = 0; i < total; i++) {
70                 var idx = (count++) % total;
71                 destination.next(ring[idx]);
72             }
73         }
74         destination.complete();
75     };
76     return TakeLastSubscriber;
77 }(Subscriber_1.Subscriber));
78 //# sourceMappingURL=takeLast.js.map