UNPKG

@zendesk/react-measure-timing-hooks

Version:

react hooks for measuring time to interactive and time to render of components

45 lines 1.88 kB
"use strict"; /** * 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.generateTimingHooks = exports.getPrefixedUseTiming = void 0; const ActionLogCache_1 = require("./ActionLogCache"); const constants_1 = require("./constants"); const getExternalApi_1 = require("./getExternalApi"); const useTiming_1 = require("./useTiming"); const getPrefixedUseTiming = ({ idPrefix, ...options }) => ({ idSuffix, ...beaconOptions } = {}, restartWhenChanged = []) => void (0, useTiming_1.useTiming)({ id: idSuffix ? `${idPrefix}/${idSuffix}` : idPrefix, ...options, ...beaconOptions, }, restartWhenChanged); exports.getPrefixedUseTiming = getPrefixedUseTiming; const generateTimingHooks = ({ name, idPrefix, garbageCollectMs = constants_1.DEFAULT_GARBAGE_COLLECT_MS, actionLogCache, ...config }, ...placements) => { const actionLogCacheInstance = actionLogCache ?? new ActionLogCache_1.ActionLogCache({ garbageCollectMs, minimumExpectedSimultaneousBeacons: placements.length, ...config, }); return Object.fromEntries(placements.flatMap((placement) => { const options = { idPrefix, actionLogCache: actionLogCacheInstance, placement, ...config, }; return [ [ `use${name}TimingIn${placement}`, (0, exports.getPrefixedUseTiming)(options), ], [`imperative${placement}TimingApi`, (0, getExternalApi_1.getExternalApi)(options)], ['actionLogCache', actionLogCacheInstance], ]; })); }; exports.generateTimingHooks = generateTimingHooks; //# sourceMappingURL=generateTimingHooks.js.map