Link Search Menu Expand Document

Using flags in code

This page describes how to use feature flags in your application.

Feature flags can be used in any application, such as a web app, mobile app, desktop app, or server backend.

AppFlags client

The AppFlags client needs to be initialized once in your application, before feature flags are to be consumed.

For more information see Setting up the SDK.

Getting feature flags

Feature flags can be retrieved from the client by specifying the flag’s key.

For example, in JavaScript you would retrieve a flag like this:

AppFlags.getFlag("my_feature", flag => {
    const flagValue = flag.value;
});

The flag’s value will be in the type specified by the flag’s variation type.

Subscribing to feature flag changes

Rather than loading a flag once, you can subscribe to a feature flag to receive future changes.

A feature flag subscription can be created from the client by specifying the flag’s key.

For example, in JavaScript you would subscribe to a flag like this:

AppFlags.onFlagChanged("my_feature", flag => {
    const flagValue = flag.value;
});

The subscription will immediately return with the flag’s current value.

If the feature flag is updated, the subscription will be invoked within a few seconds with the flag’s updated value.

More information

For more information on how to incorporate AppFlags into your code, refer to the SDK Documentation.


© 2020 AppFlags