/** * @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 { BehaviorSubject } from 'rxjs'; /** Subject used to dispatch and listen for changes to the auto change detection status . */ const autoChangeDetectionSubject = new BehaviorSubject({ isDisabled: false, }); /** The current subscription to `autoChangeDetectionSubject`. */ let autoChangeDetectionSubscription; /** * The default handler for auto change detection status changes. This handler will be used if the * specific environment does not install its own. * @param status The new auto change detection status. */ function defaultAutoChangeDetectionHandler(status) { status.onDetectChangesNow?.(); } /** * Allows a test `HarnessEnvironment` to install its own handler for auto change detection status * changes. * @param handler The handler for the auto change detection status. */ export function handleAutoChangeDetectionStatus(handler) { stopHandlingAutoChangeDetectionStatus(); autoChangeDetectionSubscription = autoChangeDetectionSubject.subscribe(handler); } /** Allows a `HarnessEnvironment` to stop handling auto change detection status changes. */ export function stopHandlingAutoChangeDetectionStatus() { autoChangeDetectionSubscription?.unsubscribe(); autoChangeDetectionSubscription = null; } /** * Batches together triggering of change detection over the duration of the given function. * @param fn The function to call with batched change detection. * @param triggerBeforeAndAfter Optionally trigger change detection once before and after the batch * operation. If false, change detection will not be triggered. * @return The result of the given function. */ async function batchChangeDetection(fn, triggerBeforeAndAfter) { // If change detection batching is already in progress, just run the function. if (autoChangeDetectionSubject.getValue().isDisabled) { return await fn(); } // If nothing is handling change detection batching, install the default handler. if (!autoChangeDetectionSubscription) { handleAutoChangeDetectionStatus(defaultAutoChangeDetectionHandler); } if (triggerBeforeAndAfter) { await new Promise(resolve => autoChangeDetectionSubject.next({ isDisabled: true, onDetectChangesNow: resolve, })); // The function passed in may throw (e.g. if the user wants to make an expectation of an error // being thrown. If this happens, we need to make sure we still re-enable change detection, so // we wrap it in a `finally` block. try { return await fn(); } finally { await new Promise(resolve => autoChangeDetectionSubject.next({ isDisabled: false, onDetectChangesNow: resolve, })); } } else { autoChangeDetectionSubject.next({ isDisabled: true }); // The function passed in may throw (e.g. if the user wants to make an expectation of an error // being thrown. If this happens, we need to make sure we still re-enable change detection, so // we wrap it in a `finally` block. try { return await fn(); } finally { autoChangeDetectionSubject.next({ isDisabled: false }); } } } /** * Disables the harness system's auto change detection for the duration of the given function. * @param fn The function to disable auto change detection for. * @return The result of the given function. */ export async function manualChangeDetection(fn) { return batchChangeDetection(fn, false); } /** * Resolves the given list of async values in parallel (i.e. via Promise.all) while batching change * detection over the entire operation such that change detection occurs exactly once before * resolving the values and once after. * @param values A getter for the async values to resolve in parallel with batched change detection. * @return The resolved values. */ export async function parallel(values) { return batchChangeDetection(() => Promise.all(values()), true); } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hhbmdlLWRldGVjdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvdGVzdGluZy9jaGFuZ2UtZGV0ZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBQyxlQUFlLEVBQWUsTUFBTSxNQUFNLENBQUM7QUFjbkQsNEZBQTRGO0FBQzVGLE1BQU0sMEJBQTBCLEdBQUcsSUFBSSxlQUFlLENBQTRCO0lBQ2hGLFVBQVUsRUFBRSxLQUFLO0NBQ2xCLENBQUMsQ0FBQztBQUVILGdFQUFnRTtBQUNoRSxJQUFJLCtCQUFvRCxDQUFDO0FBRXpEOzs7O0dBSUc7QUFDSCxTQUFTLGlDQUFpQyxDQUFDLE1BQWlDO0lBQzFFLE1BQU0sQ0FBQyxrQkFBa0IsRUFBRSxFQUFFLENBQUM7QUFDaEMsQ0FBQztBQUVEOzs7O0dBSUc7QUFDSCxNQUFNLFVBQVUsK0JBQStCLENBQzdDLE9BQW9EO0lBRXBELHFDQUFxQyxFQUFFLENBQUM7SUFDeEMsK0JBQStCLEdBQUcsMEJBQTBCLENBQUMsU0FBUyxDQUFDLE9BQU8sQ0FBQyx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