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

[FEATURE] Adds isFeatureExplicitlySet API #148

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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