defer.js 926 B

1234567891011121314151617181920212223
  1. // Create a deferredConfig prototype so that we can check for it when reviewing the configs later.
  2. function DeferredConfig() {}
  3. DeferredConfig.prototype.prepare = function() {};
  4. DeferredConfig.prototype.resolve = function() {};
  5. // Accept a function that we'll use to resolve this value later and return a 'deferred' configuration value to resolve it later.
  6. function deferConfig(func) {
  7. var obj = Object.create(DeferredConfig.prototype);
  8. obj.prepare = function(config, prop, property) {
  9. var original = prop[property]._original;
  10. obj.resolve = function() {
  11. var value = func.call(config, config, original);
  12. Object.defineProperty(prop, property, {value: value});
  13. return value;
  14. };
  15. Object.defineProperty(prop, property, {get: function() { return obj.resolve(); }});
  16. return obj;
  17. };
  18. return obj;
  19. }
  20. module.exports.deferConfig = deferConfig;
  21. module.exports.DeferredConfig = DeferredConfig;