diff --git a/README.md b/README.md index 6050d6ef..6e4ffb81 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,12 @@ 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 @@ -77,7 +83,7 @@ Bootstrapping refers to providing the LaunchDarkly client object with an initial #### 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 = { diff --git a/src/index.js b/src/index.js index 9ef2fced..1601c91d 100644 --- a/src/index.js +++ b/src/index.js @@ -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'; @@ -177,7 +188,8 @@ var client = { variation: variation, track: track, on: on, - off: off + off: off, + allFlags: allFlags }; function lsKey(env, user) {