Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for defered configuration values. #164

Merged
merged 1 commit into from Nov 14, 2014

Conversation

markstos
Copy link
Collaborator

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:

    test/3-deferred-configs.js
   test/config/default-defer.js
   test/config/local-defer.js

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.

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:

        test/3-deferred-configs.js
        test/config/default-defer.js
        test/config/local-defer.js
@lorenwest
Copy link
Collaborator

This looks good, and thanks for establishing a pattern for isolating tests!

Would you mind writing this up on the wiki? I'll get the code merged and pushed up to npm.

@lorenwest lorenwest closed this Nov 14, 2014
@lorenwest lorenwest reopened this Nov 14, 2014
lorenwest added a commit that referenced this pull request Nov 14, 2014
Add support for defered configuration values.
@lorenwest lorenwest merged commit ce554af into node-config:master Nov 14, 2014
@lorenwest
Copy link
Collaborator

Published in node-config 1.8.0

@markstos
Copy link
Collaborator Author

This looks good, and thanks for establishing a pattern for isolating tests!
Would you mind writing this up on the wiki?

I wrote up the deferred config feature. Or did you mean writing up the testing approach as well?

I could add a new page for node-config contributors if that's of interest.

Speaking of which, thanks for adding my gravatar to the contributors section. :)

@markstos markstos deleted the deferConfig branch November 14, 2014 14:31
@lorenwest
Copy link
Collaborator

I meant the deferred config feature. The test code is good documentation for test isolation :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants