Skip to content
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,20 @@ Out of the box, initializing the client will make a remote request to LaunchDark

*Note*: Feature flags must marked available to the client-side SDK (see your feature flag's settings page) before they can be used in variation calls on the front-end. If you request a feature flag that is not available, you'll receive the default value for that flag.

You can also fetch all feature flags for a user:


var flags = client.allFlags();

This will return a key / value map of all your feature flags. The map will contain `null` values for any flags that would return the fallback value (the second argument that you normally pass to `variation`). Note that this will send analytics events to LaunchDarkly as if you'd called `variation` for every feature flag.

### Bootstrapping

Bootstrapping refers to providing the LaunchDarkly client object with an initial, immediately available set of feature flag values so that on page load `variation` can be called with no delay.

#### From the server-side SDK

The preferred approach to bootstrapping is to populate the bootstrap values (a map of feature flag keys to flag values) from your backend. LaunchDarkly's server-side SDKs have a function called `all_flags`-- this function provides the initial set of bootstrap values. You can then provide these values to your front-end as a template. Depending on your templating language, this might look something like this:
The preferred approach to bootstrapping is to populate the bootstrap values (a map of feature flag keys to flag values) from your backend. LaunchDarkly's server-side SDKs have a function called `allFlags`-- this function provides the initial set of bootstrap values. You can then provide these values to your front-end as a template. Depending on your templating language, this might look something like this:

var user = {key: 'user.example.com'};
var client = LDClient.initialize('YOUR_ENVIRONMENT_ID', user, options = {
Expand Down
14 changes: 13 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ function variation(key, defaultValue) {
return value;
}

function allFlags() {
var results = {};
for (var key in flags) {
if (flags.hasOwnProperty(key)) {
results[key] = variation(key, null);
}
}

return results;
}

function track(key, data) {
if (typeof key !== 'string') {
throw 'Event key must be a string';
Expand Down Expand Up @@ -177,7 +188,8 @@ var client = {
variation: variation,
track: track,
on: on,
off: off
off: off,
allFlags: allFlags
};

function lsKey(env, user) {
Expand Down