sipp
Version:
An Opinionated, High-Productivity MVC Web Framework in TypeScript
31 lines • 1.03 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.initStore = exports.getStore = exports.hasStore = exports.Store = void 0;
const async_local_storage_1 = __importDefault(require("async-local-storage"));
async_local_storage_1.default.enable();
class Store extends Map {
}
exports.Store = Store;
const hasStore = () => {
return !!async_local_storage_1.default.get('store');
};
exports.hasStore = hasStore;
const getStore = () => {
const store = async_local_storage_1.default.get('store');
if (!store) {
throw new Error('store has not been set');
}
return store;
};
exports.getStore = getStore;
const initStore = () => {
async_local_storage_1.default.scope();
const store = new Store();
async_local_storage_1.default.set('store', store);
return store;
};
exports.initStore = initStore;
//# sourceMappingURL=index.js.map