Using the JavaScript SDK
Getting a Feature Flag
To retrieve a Feature Flag, use the getFlag
function:
AppFlags.getFlag("flag_key", flag => {
const value = flag.value;
});
Subscribing to a Feature Flag
To subscribe to a Feature Flag and get realtime updates, use the onFlagChanged
function:
AppFlags.onFlagChanged("flag_key", flag => {
const value = flag.value;
});
When the feature flag is updated, onFlagChanged
will be invoked immediately.
Note that onFlagChanged
resolves with the current Feature Flag, so there is no need to call getFlag
as well.
Flag Properties
The Flag
object contains the following properties:
key
: the key identifier for the Feature Flagvalue
: the value of the active Variation, either aboolean
,number
, orstring
Example Repository
For a full example of using AppFlags in a JavaScript application, see https://github.com/AppFlags/example-javascript.