-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValueResolvingConfig.js
35 lines (31 loc) · 1.16 KB
/
ValueResolvingConfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* eslint-disable import/extensions */
import DelegatingConfig from './DelegatingConfig.js';
export default class ValueResolvingConfig extends DelegatingConfig {
constructor(config, resolver, path, async) {
super(config, path);
const self = this;
this.resolver = resolver;
if (this.config && !async) {
this.resolved_config = resolver.resolve(this.path == null ? config : this.config.get(path));
Object.assign(self, this.resolved_config);
}
ValueResolvingConfig.prototype.has = DelegatingConfig.prototype.has;
}
get(path, defaultValue) {
if ((typeof defaultValue !== 'undefined') && this.has(path) === false) {
return defaultValue;
}
return new ValueResolvingConfig(this.config, this.resolver, path).resolved_config;
}
async fetch(path, defaultValue) {
const self = this;
if (defaultValue && this.has(path) === false) {
return defaultValue;
}
const asyncConfig = new ValueResolvingConfig(this.config, this.resolver, path, true);
return asyncConfig.resolver.asyncResolve(
asyncConfig.path == null ? asyncConfig : asyncConfig.config.get(asyncConfig.path),
self, path,
);
}
}