all files / src/ pollingLink.js

89.74% Statements 35/39
52.94% Branches 9/17
84.62% Functions 11/13
94.44% Lines 34/36
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51              11×     10× 10×                
"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Observable = require("zen-observable");
var link_1 = require("./link");
var PollingLink = (function (_super) {
    __extends(PollingLink, _super);
    function PollingLink(pollInterval) {
        var _this = _super.call(this) || this;
        _this.pollInterval = pollInterval;
        return _this;
    }
    PollingLink.prototype.request = function (operation, forward) {
        var _this = this;
        return new Observable(function (observer) {
            var subscriber = {
                next: function (data) {
                    observer.next(data);
                },
                error: function (error) { return observer.error(error); },
            };
            var poll = (function () {
                _this.subscription.unsubscribe();
                _this.subscription = forward(operation).subscribe(subscriber);
            });
            var interval = _this.pollInterval(operation);
            Eif (interval !== null) {
                _this.timer = setInterval(poll, interval);
            }
            _this.subscription = forward(operation).subscribe(subscriber);
            return function () {
                Eif (_this.timer) {
                    clearInterval(_this.timer);
                }
                _this.subscription.unsubscribe();
            };
        });
    };
    return PollingLink;
}(link_1.ApolloLink));
exports.default = PollingLink;
//# sourceMappingURL=pollingLink.js.map