FeatureGate
Import :
const FeatureGate = brackets.getModule("utils/FeatureGate")
utils/FeatureGate
FeatureGate defines util methods for enabling or disabling features in development based on a flag in local storage.
A global window.FeatureGate
object is made available in phoenix that can be called anytime after AppStart.
Usage
For Eg. You may have an extensions in development that colors phoenix in red. But you are working on a new feature that makes other colors available, but not yet ready for use. So put the extension behind a named feature gate so that only people who want to test the extension will be able to use it.
creating a feature gate
Example
// within extensions
const FeatureGate = brackets.getModule("utils/FeatureGate"); // replace with `require` for core modules.
const FEATURE_NEW_COLORS = 'myExtension.newColors';
FeatureGate.registerFeatureGate(FEATURE_NEW_COLORS, false); // false is the default value
checking if a feature is gated
Once the feature is registered, use the below code to check if the feature can be safely enabled. For Eg., if you want to enable fancy colors based on the example above: Example
if(FeatureGate.isFeatureEnabled(FEATURE_NEW_COLORS)){
// do fancy colors here
}
Enabling features for testing
- Open developer tools > local storage
- Add a new key with the key you have specified for the feature gate.
In the above Eg., the key is
myExtension.newColors
- set the value in local storage to
enabled
to enable the feature or anything else to disable.
- utils/FeatureGate
- .FEATURE_REGISTERED :
string
- .registerFeatureGate(featureName, enabledDefault) :
function
- .getAllRegisteredFeatures() ⇒
Array.<string>
- .isFeatureEnabled(featureName) ⇒
boolean
- .setFeatureEnabled(featureName, isEnabled)
- .FEATURE_REGISTERED :
utils/FeatureGate.FEATURE_REGISTERED : string
Feature gate registered
Kind: inner constant of utils/FeatureGate
utils/FeatureGate.registerFeatureGate(featureName, enabledDefault) : function
Registers a named feature with the default enabled state.
To register a feature gate with name myExtension.newColors
const FEATURE_NEW_COLORS = 'myExtension.newColors';
FeatureGate.registerFeatureGate(FEATURE_NEW_COLORS, false); // false is the default value here
Kind: inner method of utils/FeatureGate
Param | Type |
---|---|
featureName | string |
enabledDefault | boolean |
utils/FeatureGate.getAllRegisteredFeatures() ⇒ Array.<string>
Returns an array of all named registered feature gates.
Kind: inner method of utils/FeatureGate
Returns: Array.<string>
- list of registered features
utils/FeatureGate.isFeatureEnabled(featureName) ⇒ boolean
Returns true is an featureGate is enabled either by default or overridden by the user using local storage.
To check if the feature myExtension.newColors
is enabled
const FEATURE_NEW_COLORS = 'myExtension.newColors';
if(FeatureGate.isFeatureEnabled(FEATURE_NEW_COLORS))
Kind: inner method of utils/FeatureGate
Param | Type |
---|---|
featureName | string |
utils/FeatureGate.setFeatureEnabled(featureName, isEnabled)
Sets the enabled state of a specific feature in the application.
Kind: inner method of utils/FeatureGate
Param | Type | Description |
---|---|---|
featureName | string | The name of the feature to be modified. |
isEnabled | boolean | A boolean flag indicating whether the feature should be enabled (true) or disabled (false). |