UNPKG

2.77 kBJavaScriptView Raw
1import { __read, __values } from "tslib";
2import { mergeMaps, objectToMap } from "./collections.js";
3export function setup(config, runtime) {
4 if (runtime === void 0) { runtime = DefaultRuntime; }
5 runtime.assign(config);
6}
7// lable mapping for known config values
8var s = [
9 "defaultCachingStore",
10 "defaultCachingTimeoutSeconds",
11 "globalCacheDisable",
12 "enableCacheExpiration",
13 "cacheExpirationIntervalMilliseconds",
14 "spfxContext",
15 "ie11",
16];
17var runtimeCreateHooks = [];
18export function onRuntimeCreate(hook) {
19 if (runtimeCreateHooks.indexOf(hook) < 0) {
20 // apply hook logic to default runtime
21 hook(DefaultRuntime);
22 runtimeCreateHooks.push(hook);
23 }
24}
25var Runtime = /** @class */ (function () {
26 function Runtime(_v) {
27 var _this = this;
28 if (_v === void 0) { _v = new Map(); }
29 this._v = _v;
30 var defaulter = function (key, def) {
31 if (!_this._v.has(key)) {
32 _this._v.set(key, def);
33 }
34 };
35 // setup defaults
36 defaulter(s[0], "session");
37 defaulter(s[1], 60);
38 defaulter(s[2], false);
39 defaulter(s[3], false);
40 defaulter(s[4], 750);
41 defaulter(s[5], null);
42 defaulter(s[6], false);
43 runtimeCreateHooks.forEach(function (hook) { return hook(_this); });
44 }
45 /**
46 *
47 * @param config The set of properties to add to this runtime instance
48 */
49 Runtime.prototype.assign = function (config) {
50 this._v = mergeMaps(this._v, objectToMap(config));
51 };
52 /**
53 * Gets a runtime value using T to define the available keys, and R to define the type returned by that key
54 *
55 * @param key
56 */
57 Runtime.prototype.get = function (key) {
58 return this._v.get(key);
59 };
60 /**
61 * Exports the internal Map representing this runtime
62 */
63 Runtime.prototype.export = function () {
64 var e_1, _a;
65 var expt = new Map();
66 try {
67 for (var _b = __values(this._v), _c = _b.next(); !_c.done; _c = _b.next()) {
68 var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
69 if (key !== "__isDefault__") {
70 expt.set(key, value);
71 }
72 }
73 }
74 catch (e_1_1) { e_1 = { error: e_1_1 }; }
75 finally {
76 try {
77 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
78 }
79 finally { if (e_1) throw e_1.error; }
80 }
81 return expt;
82 };
83 return Runtime;
84}());
85export { Runtime };
86// default runtime used globally
87var _runtime = new Runtime(new Map([["__isDefault__", true]]));
88export var DefaultRuntime = _runtime;
89//# sourceMappingURL=libconfig.js.map
\No newline at end of file