/**
 *
 * carbon-angular v0.0.0 | animation-frame.service.js
 *
 * Copyright 2014, 2020 IBM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


import { Injectable, NgZone } from "@angular/core";
import { Subject, from } from "rxjs";
var AnimationFrameServiceSingleton = /** @class */ (function () {
    function AnimationFrameServiceSingleton(ngZone) {
        var _this = this;
        this.ngZone = ngZone;
        this.frameSource = new Subject();
        this.tick = this.frameSource.asObservable();
        this.ngZone.runOutsideAngular(function () {
            _this.animationFrameId = requestAnimationFrame(_this.doTick.bind(_this));
        });
    }
    AnimationFrameServiceSingleton.prototype.ngOnDestroy = function () {
        cancelAnimationFrame(this.animationFrameId);
    };
    AnimationFrameServiceSingleton.prototype.doTick = function (frame) {
        var _this = this;
        this.frameSource.next(frame);
        this.ngZone.runOutsideAngular(function () {
            requestAnimationFrame(_this.doTick.bind(_this));
        });
    };
    AnimationFrameServiceSingleton.decorators = [
        { type: Injectable },
    ];
    /** @nocollapse */
    AnimationFrameServiceSingleton.ctorParameters = function () { return [
        { type: NgZone }
    ]; };
    return AnimationFrameServiceSingleton;
}());
export { AnimationFrameServiceSingleton };
var AnimationFrameService = /** @class */ (function () {
    function AnimationFrameService(singleton) {
        this.singleton = singleton;
        this.tick = from(this.singleton.tick);
    }
    AnimationFrameService.decorators = [
        { type: Injectable },
    ];
    /** @nocollapse */
    AnimationFrameService.ctorParameters = function () { return [
        { type: AnimationFrameServiceSingleton }
    ]; };
    return AnimationFrameService;
}());
export { AnimationFrameService };
//# sourceMappingURL=animation-frame.service.js.map