m8ty_feature_flags
What features exist and how can the features be activated/deactivated based on some information (user, application, version, timing etc.)? This library should be used for the integration inside the app relaying on the configuration of those flags. Based on the flag a feature will be displayed or not. This library supports the app in reading the flags and rendering the widgets based on those flags.
Setup the package
Define all the features using type safety
Using string as feature names is not an option. A possible approach is to use enums
Install package
Initialize the package
Parameter | Description |
|---|---|
apiKey | Key configured on the server so that you can access the API |
features | A list of all available features and if those features are enabled or disabled by default |
baseUrl | Url to the server API responsible for tracking |
refreshInterval | How often should the configuration be retrieved from the server. Initial retrieve happens during the app startup |
callback | Callback is being called whenever a feature is being rendered. This is very helpful for analytics |
Check if a feature is enabled
There are different options to check if a certain feature is active. Based on the feature flag, the application may change its behavior.
Check if one feature is enabled
This is the simplest use case. We have one feature and we are checking if its active or not
Check if one feature is disabled
Check if all features in the list are enabled
Check if any of the features in the list is enabled
Therefore the property requirement is used with the value FeatureRequirement.any. The default is FeatureRequirement.all and is used in all the examples above.
Negation
Of course the negation of the condition can be set as well. This means the evaluated output will be negated (NOT)
Conditional rendering of widgets
But how now based on the feature flag to display a widget or not. Therefore the M8tyFeature has been introduced
If all the features being defined in the featureKeys are enabled, then the widget will be rendered. Of course all the above listed options are available.
Parameter | Description |
|---|---|
featureKeys | List of features which should be checked |
child | Child control which should be rendered if the feature is enabled |
requirement | Are all features required to render the child widget |
negate | Negate the condition of features list |
type | Supporting widget or is it the real feature. The configuration is relevant for analytics |
name | Optional name for the feature which is about to be reported to callback function defined during initialize. Also relevant for analytics |
Analytics integration
For tracking integration there is an extra callback which is only being called in combination with the M8tyFeature widget. Please see therefore the callback named parameter in the initialize method. Here the data being passed in during the callback
Use without the server
If you want use the features without getting the flags from the server, all you need to do is not to set the api key. This way no requests will be sent toward the server.