tethys-feature-service/node_modules/config/defer.js

24 lines
926 B
JavaScript
Raw Normal View History

2023-10-02 13:04:02 +00:00
// Create a deferredConfig prototype so that we can check for it when reviewing the configs later.
function DeferredConfig() {}
DeferredConfig.prototype.prepare = function() {};
DeferredConfig.prototype.resolve = function() {};
// Accept a function that we'll use to resolve this value later and return a 'deferred' configuration value to resolve it later.
function deferConfig(func) {
var obj = Object.create(DeferredConfig.prototype);
obj.prepare = function(config, prop, property) {
var original = prop[property]._original;
obj.resolve = function() {
var value = func.call(config, config, original);
Object.defineProperty(prop, property, {value: value});
return value;
};
Object.defineProperty(prop, property, {get: function() { return obj.resolve(); }});
return obj;
};
return obj;
}
module.exports.deferConfig = deferConfig;
module.exports.DeferredConfig = DeferredConfig;