configcat-react
Version:
ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.
28 lines (27 loc) • 1.15 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConfigCatContext = exports.ensureConfigCatContext = void 0;
var react_1 = __importDefault(require("react"));
/** @remarks Map key: provider id normalized to lower case. */
var ConfigCatContextRegistry = new Map();
function registryKeyFor(providerId) {
return providerId ? providerId.toLowerCase() : "";
}
function ensureConfigCatContext(providerId) {
var key = registryKeyFor(providerId);
var context = ConfigCatContextRegistry.get(key);
if (!context) {
context = react_1.default.createContext(void 0);
context.displayName = "ConfigCatContext" + (providerId ? "_" + providerId : "");
ConfigCatContextRegistry.set(key, context);
}
return context;
}
exports.ensureConfigCatContext = ensureConfigCatContext;
function getConfigCatContext(providerId) {
return ConfigCatContextRegistry.get(registryKeyFor(providerId));
}
exports.getConfigCatContext = getConfigCatContext;