Skip to content

Commit

Permalink
[FEATURE] Adds isFeatureExplicitlySet API
Browse files Browse the repository at this point in the history
This API lets us check if a feature is explicitly set (e.g. given a
value in the config)
  • Loading branch information
Chris Garrett committed Oct 23, 2019
1 parent 625aa48 commit 6201c70
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ included() {
}
```
It also exposes a method called `isFeatureExplicitlySet`, which can be used to check whether or not the user has explictly set the value of the option instead of using the default.
### At run-time (from an app or addon)
WIP -- there does not yet exist a public API for accessing the state of optional features at runtime. [This](https://github.com/pzuraq/ember-compatibility-helpers/issues/27) issue is tracking it.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ module.exports = {
return value !== undefined ? value : FEATURES[name].default;
},

isFeatureExplicitlySet(name) {
return this._features[name] !== undefined;
},

config() {
let EmberENV = {};
let features = this._features;
Expand Down
9 changes: 9 additions & 0 deletions tests/optional-features-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ QUnit.module('@ember/optional-features', hooks => {
assert.strictEqual(addon.isFeatureEnabled('template-only-glimmer-components'), false, 'Expecting default value');
});

QUnit.test('it can query the features with `isFeatureExplicitlySet`', assert => {
let addon = buildAddon({
'application-template-wrapper': false
});

assert.strictEqual(addon.isFeatureExplicitlySet('application-template-wrapper'), true, 'Expecting value to exist');
assert.strictEqual(addon.isFeatureExplicitlySet('template-only-glimmer-components'), false, 'Expecting to not exist');
});

QUnit.test('it allows the config to be a overridden with an ENV variable', assert => {
process.env.EMBER_OPTIONAL_FEATURES = `{ "application-template-wrapper": false }`;

Expand Down

0 comments on commit 6201c70

Please sign in to comment.