Add support for defered configuration values. #164
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As seen in the included tests, a new feature is added to allow you declare a
configuration value as a special kind of function in .js files.
This is useful to create default configuration values based on other
configuration values when other further configuration files may override the
values being referenced.
You can think of this as allowing you declare "templates" which contain
variables referencing other config values in the configuration file, which are
then "rendered" with the correct values once all the config files have been
loaded in merged.
One test shows that the addition is backwards compatible with config files
that have been using functions as values. Only functions which are instance of
the newly provided DeferredConfig class are handled specially.
For example use see:
I looked for other names to avoid the name 'defer' and 'deferred', since 'deferred' is used
by some promise library. Finding nothing that better conveyed what this feature does, I settled
on the name 'deferConfig', which will not conflict with promise libraries name of 'defer' or 'deferred'.
However, people can alias the name to simply 'defer()' in their config files upon import if they
prefer the shorter name.
Note also the use of module un-loading / reloading in the new test file.
I found adding tests to the "2" test file to be challenging because it references
so many configuration files and values with a complex cascading relationship.
By using the unload/reload pattern, I was able to a small isolated test that is
easy to review and maintain without intefering with the existing battery of
tests.