@zendesk/react-measure-timing-hooks
Version:
react hooks for measuring time to interactive and time to render of components
104 lines (103 loc) • 4.4 kB
TypeScript
/**
* Copyright Zendesk, Inc.
*
* Use of this source code is governed under the Apache License, Version 2.0
* found at http://www.apache.org/licenses/LICENSE-2.0.
*/
import type { DependencyList } from 'react';
import type { Action, ActionWithStateMetadata, DynamicActionLogOptions, SpanAction, StageChangeAction, StaticActionLogOptions, WithOnInternalError } from './types';
import type { DistributiveOmit } from './typescriptHelpers';
export declare class ActionLog<CustomMetadata extends Record<string, unknown>> {
private actions;
private onActionAddedCallback;
private lastStage;
private lastStageUpdatedAt;
private get lastStageEntry();
private lastStageBySource;
finalStages: readonly string[];
loadingStages: readonly string[];
immediateSendReportStages: readonly string[];
private dependenciesBySource;
private hasReportedAtLeastOnce;
private flushUponDeactivation;
customMetadataBySource: Map<string, CustomMetadata>;
reportedErrors: WeakSet<object>;
/**
* Returns the PerformanceEntry from the last render, or undefined if no render has completed.
* Enables verifying whether timing beacons have rendered even outside the scope of the timingHook.
*/
getLastRenderedActionEntry(): PerformanceEntry | undefined;
getActions(): ActionWithStateMetadata[];
/**
* Clear performance marks that were added by this ActionLog instance.
*/
private clearPerformanceMarks;
/**
* Clear parts of the internal state, so it's ready for the next measurement.
*/
clear(): void;
/**
* Complete reset of internal state,
* except for configuration options which are always updated on render.
*/
reset(): void;
private reportFn;
private shouldResetOnDependencyChangeFnBySource;
private id;
wasImported: boolean;
onInternalError: Required<WithOnInternalError<CustomMetadata>>['onInternalError'];
private minimumExpectedSimultaneousBeacons?;
private placementsCurrentlyRenderable;
private waitForBeaconActivation;
get isInUse(): boolean;
getId(): string;
constructor(options: StaticActionLogOptions<string, CustomMetadata>);
updateStaticOptions({ debounceMs, timeoutMs, finalStages, loadingStages, immediateSendReportStages, minimumExpectedSimultaneousBeacons, waitForBeaconActivation, flushUponDeactivation, reportFn, onActionAddedCallback, onInternalError, }: StaticActionLogOptions<string, CustomMetadata>): void;
/**
* Use to import internal state from another ActionLog instance.
*/
importState(otherLog: ActionLog<CustomMetadata>): void;
setAsImported(): void;
updateOptions({ id, reportFn, shouldResetOnDependencyChangeFn, onInternalError, onActionAddedCallback, }: DynamicActionLogOptions<CustomMetadata>, source: string): void;
/**
* Inserts an action while maintaining order
* @returns {boolean} true when inserted at the very end of actions
*/
private insertActionInOrder;
addSpan(info: DistributiveOmit<SpanAction, 'timestamp' | 'marker'>): void;
addAction(...actions: Action[]): void;
private addStageChange;
private willFlushTimeout?;
private onActionAdded;
get lastStageChange(): StageChangeAction | undefined;
markStage(info: Omit<StageChangeAction, 'type' | 'marker' | 'timestamp' | 'entry'>): void;
private _shouldReport;
get shouldReport(): boolean;
ensureReporting(): void;
disableReporting(): void;
private observer;
private _isObserving;
get isObserving(): boolean;
private observe;
stopObserving(): void;
private isCapturingDataBySource;
onBeaconRemoved(source: string): void;
private dispose;
private onDisposeCallbacks;
/**
* schedule action to be called once the ActionLog is no longer used
* @param callback
*/
onDispose(name: string, callback: () => void): void;
get isCapturingData(): boolean;
setActive(active: boolean, source: string): void;
get isInFinalStage(): boolean;
get isInImmediateSendStage(): boolean;
private getRenderedCountBySource;
private get lastRenderAction();
private markDependencyChange;
onExternalDependenciesChange(newDependencies: DependencyList, timestamp: PerformanceMark, source: string): void;
private trigger;
private debounceOptionsRef;
private debouncedTrigger;
}