UNPKG

@itwin/certa

Version:

A mocha-based integration test runner

33 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCallbacksRegisteredOnBackend = getCallbacksRegisteredOnBackend; exports.executeRegisteredCallback = executeRegisteredCallback; exports.registerBackendCallback = registerBackendCallback; exports.executeBackendCallback = executeBackendCallback; const isFrontend = (typeof (window) !== "undefined"); /** @internal */ function getCallbacksRegisteredOnBackend() { if (isFrontend) throw new Error("This should only be called on the backend!"); global._CertaRegisteredCallbacks = global._CertaRegisteredCallbacks || {}; return global._CertaRegisteredCallbacks; } /** @internal */ function executeRegisteredCallback(name, args) { const registeredCallbacks = getCallbacksRegisteredOnBackend(); if (!(name in registeredCallbacks)) throw new Error(`Unknown certa backend callback "${name}"`); return registeredCallbacks[name](...args); } function registerBackendCallback(name, cb) { if (isFrontend) throw new Error("This should only be called on the backend!"); global._CertaRegisteredCallbacks = global._CertaRegisteredCallbacks || {}; global._CertaRegisteredCallbacks[name] = cb; } async function executeBackendCallback(name, ...args) { if (!isFrontend) return executeRegisteredCallback(name, args); return window._CertaSendToBackend(name, args); } //# sourceMappingURL=CallbackUtils.js.map