From 58901a74b70d7e2ab9bc6ed472306c4e07f5e325 Mon Sep 17 00:00:00 2001 From: John Kodumal Date: Tue, 13 Sep 2016 20:54:59 -0700 Subject: [PATCH 1/3] Add all_flags method to the client --- README.md | 6 ++++++ src/index.js | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6050d6ef..03e56c94 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.all_flags(); + +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 diff --git a/src/index.js b/src/index.js index 9ef2fced..58e594f6 100644 --- a/src/index.js +++ b/src/index.js @@ -99,6 +99,17 @@ function variation(key, defaultValue) { return value; } +function all_flags() { + 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, + all_flags: all_flags }; function lsKey(env, user) { From 704c3634b914763ac5700502984da3a070652e7e Mon Sep 17 00:00:00 2001 From: John Kodumal Date: Wed, 14 Sep 2016 10:12:11 -0700 Subject: [PATCH 2/3] all_flags -> allFlags --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 58e594f6..1601c91d 100644 --- a/src/index.js +++ b/src/index.js @@ -99,7 +99,7 @@ function variation(key, defaultValue) { return value; } -function all_flags() { +function allFlags() { var results = {}; for (var key in flags) { if (flags.hasOwnProperty(key)) { @@ -189,7 +189,7 @@ var client = { track: track, on: on, off: off, - all_flags: all_flags + allFlags: allFlags }; function lsKey(env, user) { From eb493a951cf4959cf856947f83550f052b49557e Mon Sep 17 00:00:00 2001 From: John Kodumal Date: Wed, 14 Sep 2016 10:19:15 -0700 Subject: [PATCH 3/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 03e56c94..6e4ffb81 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Out of the box, initializing the client will make a remote request to LaunchDark You can also fetch all feature flags for a user: - var flags = client.all_flags(); + 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. @@ -83,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 = {