telefunc
Version:
Remote functions. Instead of API.
39 lines (38 loc) • 1.46 kB
JavaScript
export { getContext };
export { provideTelefuncContext };
export { restoreContext };
export { installAsyncMode };
export { isAsyncMode };
import { getContext_sync, provideTelefuncContext_sync, restoreContext_sync } from './getContext/sync.js';
import { assert, isObject, getGlobalObject } from '../utils.js';
const globalObject = getGlobalObject('getContext.ts', {
getContext: getContext_sync,
restoreContext: restoreContext_sync,
provideTelefuncContext: provideTelefuncContext_sync,
isAsyncMode: false,
});
function getContext() {
const context = globalObject.getContext();
assert(isObject(context));
return context;
}
function provideTelefuncContext(context) {
/* TODO: check whether it's possible to deprecate Async Hooks for Nuxt.
assertWarning(false, 'provideTelefuncContext() is deprecated', { onlyOnce: true })
*/
assert(isObject(context));
globalObject.provideTelefuncContext(context);
}
function restoreContext(context) {
assert(context === null || isObject(context));
globalObject.restoreContext(context);
}
function installAsyncMode({ getContext_async, provideTelefuncContext_async, restoreContext_async, }) {
globalObject.getContext = getContext_async;
globalObject.restoreContext = restoreContext_async;
globalObject.provideTelefuncContext = provideTelefuncContext_async;
globalObject.isAsyncMode = true;
}
function isAsyncMode() {
return globalObject.isAsyncMode;
}