/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { Injectable, NgZone, InjectionToken } from '@angular/core'; import { from, Subject } from 'rxjs'; import { take, takeUntil } from 'rxjs/operators'; import * as i0 from "@angular/core"; /** * @docs-private */ export class _Schedule { constructor() { this.tasks = []; this.endTasks = []; } } /** Injection token used to provide a coalesced style scheduler. */ export const _COALESCED_STYLE_SCHEDULER = new InjectionToken('_COALESCED_STYLE_SCHEDULER'); /** * Allows grouping up CSSDom mutations after the current execution context. * This can significantly improve performance when separate consecutive functions are * reading from the CSSDom and then mutating it. * * @docs-private */ export class _CoalescedStyleScheduler { constructor(_ngZone) { this._ngZone = _ngZone; this._currentSchedule = null; this._destroyed = new Subject(); } /** * Schedules the specified task to run at the end of the current VM turn. */ schedule(task) { this._createScheduleIfNeeded(); this._currentSchedule.tasks.push(task); } /** * Schedules the specified task to run after other scheduled tasks at the end of the current * VM turn. */ scheduleEnd(task) { this._createScheduleIfNeeded(); this._currentSchedule.endTasks.push(task); } /** Prevent any further tasks from running. */ ngOnDestroy() { this._destroyed.next(); this._destroyed.complete(); } _createScheduleIfNeeded() { if (this._currentSchedule) { return; } this._currentSchedule = new _Schedule(); this._getScheduleObservable() .pipe(takeUntil(this._destroyed)) .subscribe(() => { while (this._currentSchedule.tasks.length || this._currentSchedule.endTasks.length) { const schedule = this._currentSchedule; // Capture new tasks scheduled by the current set of tasks. this._currentSchedule = new _Schedule(); for (const task of schedule.tasks) { task(); } for (const task of schedule.endTasks) { task(); } } this._currentSchedule = null; }); } _getScheduleObservable() { // Use onStable when in the context of an ongoing change detection cycle so that we // do not accidentally trigger additional cycles. return this._ngZone.isStable ? from(Promise.resolve(undefined)) : this._ngZone.onStable.pipe(take(1)); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: _CoalescedStyleScheduler, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: _CoalescedStyleScheduler }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: _CoalescedStyleScheduler, decorators: [{ type: Injectable }], ctorParameters: function () { return [{ type: i0.NgZone }]; } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29hbGVzY2VkLXN0eWxlLXNjaGVkdWxlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvdGFibGUvY29hbGVzY2VkLXN0eWxlLXNjaGVkdWxlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsVUFBVSxFQUFFLE1BQU0sRUFBYSxjQUFjLEVBQUMsTUFBTSxlQUFlLENBQUM7QUFDNUUsT0FBTyxFQUFDLElBQUksRUFBRSxPQUFPLEVBQUMsTUFBTSxNQUFNLENBQUM7QUFDbkMsT0FBTyxFQUFDLElBQUksRUFBRSxTQUFTLEVBQUMsTUFBTSxnQkFBZ0IsQ0FBQzs7QUFFL0M7O0dBRUc7QUFDSCxNQUFNLE9BQU8sU0FBUztJQUF0QjtRQUNFLFVBQUssR0FBc0IsRUFBRSxDQUFDO1FBQzlCLGFBQVEsR0FBc0IsRUFBRSxDQUFDO0lBQ25DLENBQUM7Q0FBQTtBQUVELG1FQUFtRTtBQUNuRSxNQUFNLENBQUMsTUFBTSwwQkFBMEIsR0FBRyxJQUFJLGNBQWMsQ0FDMUQsNEJBQTRCLENBQzdCLENBQUM7QUFFRjs7Ozs7O0dBTUc7QUFFSCxNQUFNLE9BQU8sd0JBQXdCO0lBSW5DLFlBQTZCLE9BQWU7UUFBZixZQUFPLEdBQVAsT0FBTyxDQUFRO1FBSHBD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