Files
klz-cables.com/.pnpm-store/v10/files/70/4c229248a0feb353c83c32da344e620c5f54c6c22551c8f5441f1433956daaf3f2a4bc537419ce5f99b6ef9128fae263909db49d059db8bab7d67a904b6673
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

59 lines
1.5 KiB
Plaintext

import { DEBUG_BUILD } from '../debug-build.js';
import { debug } from '../utils/debug-logger.js';
import { getFunctionName } from '../utils/stacktrace.js';
// We keep the handlers globally
const handlers = {};
const instrumented = {};
/** Add a handler function. */
function addHandler(type, handler) {
handlers[type] = handlers[type] || [];
handlers[type].push(handler);
}
/**
* Reset all instrumentation handlers.
* This can be used by tests to ensure we have a clean slate of instrumentation handlers.
*/
function resetInstrumentationHandlers() {
Object.keys(handlers).forEach(key => {
handlers[key ] = undefined;
});
}
/** Maybe run an instrumentation function, unless it was already called. */
function maybeInstrument(type, instrumentFn) {
if (!instrumented[type]) {
instrumented[type] = true;
try {
instrumentFn();
} catch (e) {
DEBUG_BUILD && debug.error(`Error while instrumenting ${type}`, e);
}
}
}
/** Trigger handlers for a given instrumentation type. */
function triggerHandlers(type, data) {
const typeHandlers = type && handlers[type];
if (!typeHandlers) {
return;
}
for (const handler of typeHandlers) {
try {
handler(data);
} catch (e) {
DEBUG_BUILD &&
debug.error(
`Error while triggering instrumentation handler.\nType: ${type}\nName: ${getFunctionName(handler)}\nError:`,
e,
);
}
}
}
export { addHandler, maybeInstrument, resetInstrumentationHandlers, triggerHandlers };
//# sourceMappingURL=handlers.js.map