Skip to content

Commit

Permalink
Merge pull request #148 from emberjs/feat/add-is-feature-set
Browse files Browse the repository at this point in the history
[FEATURE] Adds isFeatureExplicitlySet API
  • Loading branch information
Chris Garrett authored Oct 23, 2019
2 parents 625aa48 + 6201c70 commit 37d9998
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 37d9998

Please sign in to comment.