@triviality/core
Version:
Purely typed service container
30 lines • 928 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var invokeContextStack = [];
function getCurrent() {
var context = invokeContextStack[invokeContextStack.length - 1];
if (!context) {
throw new Error('Can only be called withing withGlobalContext');
}
return context;
}
exports.getCurrentContext = function () {
return getCurrent().context;
};
exports.getCurrentFeatureFactory = function () {
return getCurrent().featureFactory;
};
exports.getCurrentContainer = function () {
return getCurrent().container;
};
exports.inCurrentContext = function () { return invokeContextStack.length !== 0; };
exports.withGlobalContext = function (context, callback) {
invokeContextStack.push(context);
try {
callback();
}
finally {
invokeContextStack.splice(invokeContextStack.indexOf(context), 1);
}
};
//# sourceMappingURL=GlobalContext.js.map
;