/**
* @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 { assertInInjectionContext, Injector, ɵɵdefineInjectable } from '../di';
import { inject } from '../di/injector_compatibility';
import { ErrorHandler } from '../error_handler';
import { RuntimeError } from '../errors';
import { DestroyRef } from '../linker/destroy_ref';
import { assertGreaterThan } from '../util/assert';
import { NgZone } from '../zone';
import { isPlatformBrowser } from './util/misc_utils';
/**
* Register a callback to be invoked each time the application
* finishes rendering.
*
* Note that the callback will run
* - in the order it was registered
* - once per render
* - on browser platforms only
*
*
*
* Components are not guaranteed to be [hydrated](guide/hydration) before the callback runs.
* You must use caution when directly reading or writing the DOM and layout.
*
*
*
* @param callback A callback function to register
*
* @usageNotes
*
* Use `afterRender` to read or write the DOM after each render.
*
* ### Example
* ```ts
* @Component({
* selector: 'my-cmp',
* template: `{{ ... }}`,
* })
* export class MyComponent {
* @ViewChild('content') contentRef: ElementRef;
*
* constructor() {
* afterRender(() => {
* console.log('content height: ' + this.contentRef.nativeElement.scrollHeight);
* });
* }
* }
* ```
*
* @developerPreview
*/
export function afterRender(callback, options) {
!options && assertInInjectionContext(afterRender);
const injector = options?.injector ?? inject(Injector);
if (!isPlatformBrowser(injector)) {
return { destroy() { } };
}
let destroy;
const unregisterFn = injector.get(DestroyRef).onDestroy(() => destroy?.());
const afterRenderEventManager = injector.get(AfterRenderEventManager);
// Lazily initialize the handler implementation, if necessary. This is so that it can be
// tree-shaken if `afterRender` and `afterNextRender` aren't used.
const callbackHandler = afterRenderEventManager.handler ??= new AfterRenderCallbackHandlerImpl();
const ngZone = injector.get(NgZone);
const errorHandler = injector.get(ErrorHandler, null, { optional: true });
const instance = new AfterRenderCallback(ngZone, errorHandler, callback);
destroy = () => {
callbackHandler.unregister(instance);
unregisterFn();
};
callbackHandler.register(instance);
return { destroy };
}
/**
* Register a callback to be invoked the next time the application
* finishes rendering.
*
* Note that the callback will run
* - in the order it was registered
* - on browser platforms only
*
*
*
* Components are not guaranteed to be [hydrated](guide/hydration) before the callback runs.
* You must use caution when directly reading or writing the DOM and layout.
*
*
*
* @param callback A callback function to register
*
* @usageNotes
*
* Use `afterNextRender` to read or write the DOM once,
* for example to initialize a non-Angular library.
*
* ### Example
* ```ts
* @Component({
* selector: 'my-chart-cmp',
* template: `{{ ... }}
`,
* })
* export class MyChartCmp {
* @ViewChild('chart') chartRef: ElementRef;
* chart: MyChart|null;
*
* constructor() {
* afterNextRender(() => {
* this.chart = new MyChart(this.chartRef.nativeElement);
* });
* }
* }
* ```
*
* @developerPreview
*/
export function afterNextRender(callback, options) {
!options && assertInInjectionContext(afterNextRender);
const injector = options?.injector ?? inject(Injector);
if (!isPlatformBrowser(injector)) {
return { destroy() { } };
}
let destroy;
const unregisterFn = injector.get(DestroyRef).onDestroy(() => destroy?.());
const afterRenderEventManager = injector.get(AfterRenderEventManager);
// Lazily initialize the handler implementation, if necessary. This is so that it can be
// tree-shaken if `afterRender` and `afterNextRender` aren't used.
const callbackHandler = afterRenderEventManager.handler ??= new AfterRenderCallbackHandlerImpl();
const ngZone = injector.get(NgZone);
const errorHandler = injector.get(ErrorHandler, null, { optional: true });
const instance = new AfterRenderCallback(ngZone, errorHandler, () => {
destroy?.();
callback();
});
destroy = () => {
callbackHandler.unregister(instance);
unregisterFn();
};
callbackHandler.register(instance);
return { destroy };
}
/**
* A wrapper around a function to be used as an after render callback.
*/
class AfterRenderCallback {
constructor(zone, errorHandler, callbackFn) {
this.zone = zone;
this.errorHandler = errorHandler;
this.callbackFn = callbackFn;
}
invoke() {
try {
this.zone.runOutsideAngular(this.callbackFn);
}
catch (err) {
this.errorHandler?.handleError(err);
}
}
}
/**
* Core functionality for `afterRender` and `afterNextRender`. Kept separate from
* `AfterRenderEventManager` for tree-shaking.
*/
class AfterRenderCallbackHandlerImpl {
constructor() {
this.executingCallbacks = false;
this.callbacks = new Set();
this.deferredCallbacks = new Set();
}
validateBegin() {
if (this.executingCallbacks) {
throw new RuntimeError(102 /* RuntimeErrorCode.RECURSIVE_APPLICATION_RENDER */, ngDevMode &&
'A new render operation began before the previous operation ended. ' +
'Did you trigger change detection from afterRender or afterNextRender?');
}
}
register(callback) {
// If we're currently running callbacks, new callbacks should be deferred
// until the next render operation.
const target = this.executingCallbacks ? this.deferredCallbacks : this.callbacks;
target.add(callback);
}
unregister(callback) {
this.callbacks.delete(callback);
this.deferredCallbacks.delete(callback);
}
execute() {
this.executingCallbacks = true;
for (const callback of this.callbacks) {
callback.invoke();
}
this.executingCallbacks = false;
for (const callback of this.deferredCallbacks) {
this.callbacks.add(callback);
}
this.deferredCallbacks.clear();
}
destroy() {
this.callbacks.clear();
this.deferredCallbacks.clear();
}
}
/**
* Implements core timing for `afterRender` and `afterNextRender` events.
* Delegates to an optional `AfterRenderCallbackHandler` for implementation.
*/
export class AfterRenderEventManager {
constructor() {
this.renderDepth = 0;
/* @internal */
this.handler = null;
}
/**
* Mark the beginning of a render operation (i.e. CD cycle).
* Throws if called while executing callbacks.
*/
begin() {
this.handler?.validateBegin();
this.renderDepth++;
}
/**
* Mark the end of a render operation. Callbacks will be
* executed if there are no more pending operations.
*/
end() {
ngDevMode && assertGreaterThan(this.renderDepth, 0, 'renderDepth must be greater than 0');
this.renderDepth--;
if (this.renderDepth === 0) {
this.handler?.execute();
}
}
ngOnDestroy() {
this.handler?.destroy();
this.handler = null;
}
/** @nocollapse */
static { this.ɵprov = ɵɵdefineInjectable({
token: AfterRenderEventManager,
providedIn: 'root',
factory: () => new AfterRenderEventManager(),
}); }
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWZ0ZXJfcmVuZGVyX2hvb2tzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvY29yZS9zcmMvcmVuZGVyMy9hZnRlcl9yZW5kZXJfaG9va3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5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