diff --git a/launchdarkly/dart/sample.dart b/launchdarkly/dart/sample.dart index d56f93d..0a81c54 100644 --- a/launchdarkly/dart/sample.dart +++ b/launchdarkly/dart/sample.dart @@ -13,20 +13,8 @@ class SampleDart { await ldClient.start(user); - bool flagValue = await ldClient.boolVariation("is-dark-mode-enabled", false); - - if (flagValue) { - // The code to run if the feature is on - print("Dark mode!"); - } else { - // The code to run if the feature is off - bool otherFlag = await ldClient.boolVariation("is-ameyas-weird-blue-theme", false); - if (otherFlag) { - print("Why? Just... why?"); - } else { - print("Light mode it is, then!"); - } - } + // The code to run if the feature is on + print("Dark mode!"); await ldClient.close(); } diff --git a/launchdarkly/go/sample.go b/launchdarkly/go/sample.go index 3dee8b6..9393962 100644 --- a/launchdarkly/go/sample.go +++ b/launchdarkly/go/sample.go @@ -22,25 +22,17 @@ import ( ) func checkFeatureFlags(user lduser.User, ldClient *ld.LDClient) { - // Check the 'is-dark-mode-enabled' feature flag for the specified user - darkModeEnabled, err := ldClient.BoolVariation("is-dark-mode-enabled", user, false) - if err != nil { - fmt.Printf("Error evaluating feature flag 'is-dark-mode-enabled': %s\n", err) - return - } // Report the status of the dark mode - fmt.Println("Dark mode is", enabledStatus(darkModeEnabled)) + fmt.Println("Dark mode is", enabledStatus(true)) // If dark mode is enabled, check for high contrast mode - if darkModeEnabled { - // Check the 'enable-high-contrast' feature flag for the specified user - highContrastEnabled, err1 := ldClient.BoolVariation("enable-high-contrast", user, false) - if err1 != nil { - fmt.Printf("Error evaluating feature flag 'enable-high-contrast': %s\n", err1) - return - } - // Report the status of the high contrast mode - fmt.Println("High contrast mode is", enabledStatus(highContrastEnabled)) + // Check the 'enable-high-contrast' feature flag for the specified user + highContrastEnabled, err1 := ldClient.BoolVariation("enable-high-contrast", user, false) + if err1 != nil { + fmt.Printf("Error evaluating feature flag 'enable-high-contrast': %s\n", err1) + return } + // Report the status of the high contrast mode + fmt.Println("High contrast mode is", enabledStatus(highContrastEnabled)) } diff --git a/launchdarkly/java/Sample.java b/launchdarkly/java/Sample.java index a93aaeb..a04aa30 100644 --- a/launchdarkly/java/Sample.java +++ b/launchdarkly/java/Sample.java @@ -21,20 +21,7 @@ class Sample { public void sampleMethodCheckingFlag() { - LDClient client = new LDClient("sdk-key-123abc"); - LDContext context = LDContext - .builder("context-key-123abc") - .name("Sandy") - .build(); - // Check the 'is-dark-mode-enabled' feature flag for the specified user - boolean flagValue = client.boolVariation("is-dark-mode-enabled", context, false); - if (flagValue) { - // The code to run if the feature is on - System.out.println("Dark mode!"); - } else { - // The code to run if the feature is off - System.out.println("My eyes, they burn!"); - } + // The code to run if the feature is on + System.out.println("Dark mode!"); } - } diff --git a/launchdarkly/java/SampleDeep.java b/launchdarkly/java/SampleDeep.java index 43a55ae..36d77b6 100644 --- a/launchdarkly/java/SampleDeep.java +++ b/launchdarkly/java/SampleDeep.java @@ -23,28 +23,8 @@ class SampleDeep { public void sampleMethodCheckingFlag(Map config) { LDClient client = new LDClient("sdk-key-123abc"); - LDContext context = LDContext - .builder("context-key-123abc") - .name("Sandy") - .build(); - // Check the 'is-dark-mode-enabled' feature flag for the specified user - boolean flagValue = isDarkModeEnabled(); - if (flagValue || forceDarkModeFromLocalConfig(config)) { - // The code to run if the feature is on - System.out.println("Dark mode!"); - } else { - // The code to run if the feature is off - System.out.println("My eyes, they burn!"); - } + LDContext context = LDContext.builder("context-key-123abc").name("Sandy").build(); + // The code to run if the feature is on + System.out.println("Dark mode!"); } - - private bool isDarkModeEnabled() { - return client.boolVariation("is-dark-mode-enabled", context, false); - } - - // A non-feature-flag related condition that's part of our check - private bool forceDarkModeFromLocalConfig(Map config) { - return config.get("dark-mode").equals("on"); - } - } diff --git a/launchdarkly/kotlin/sample.kt b/launchdarkly/kotlin/sample.kt index 23878b5..54d0027 100644 --- a/launchdarkly/kotlin/sample.kt +++ b/launchdarkly/kotlin/sample.kt @@ -20,20 +20,14 @@ import com.launchdarkly.sdk.server.LDClient fun checkFeatureFlags( user: LDUser, ldClient: LDClient, -): String { +): String { try { - // Check the 'is-dark-mode-enabled' feature flag for the specified user - val darkModeEnabled = ldClient.boolVariation("is-dark-mode-enabled", user, false) - println("Dark mode is ${enabledStatus(darkModeEnabled)}") + println("Dark mode is ${enabledStatus(true)}") // If dark mode is enabled, check for high contrast mode - if (darkModeEnabled) { - val highContrastEnabled = ldClient.boolVariation("enable-high-contrast", user, false) - println("High contrast mode is ${enabledStatus(highContrastEnabled)}") - return "Dark Mode and high contrast" - } - println("No dark mode") - return "Light mode and no high contrast" + val highContrastEnabled = ldClient.boolVariation("enable-high-contrast", user, false) + println("High contrast mode is ${enabledStatus(highContrastEnabled)}") + return "Dark Mode and high contrast" } catch (e: Exception) { println("Error evaluating feature flags: ${e.message}") } diff --git a/launchdarkly/node/sample.js b/launchdarkly/node/sample.js index 0c25516..d0e7810 100644 --- a/launchdarkly/node/sample.js +++ b/launchdarkly/node/sample.js @@ -23,24 +23,8 @@ import * as LaunchDarkly from "@launchdarkly/node-server-sdk"; const SDK_KEY = ""; -const context = { - kind: "user", - name: "Sandy", - key: "example-context-key", -}; const client = LaunchDarkly.init(SDK_KEY); client.once("ready", () => { - client.variation( - "is-dark-mode-enabled", - context, - false, - (err, useDarkMode) => { - if (useDarkMode) { - console.log("Dark mode is enabled"); - } else { - console.log("Dark mode is disabled"); - } - }, - ); + console.log("Dark mode is enabled"); }); diff --git a/launchdarkly/react/sample.tsx b/launchdarkly/react/sample.tsx index ab8c13c..32ddc62 100644 --- a/launchdarkly/react/sample.tsx +++ b/launchdarkly/react/sample.tsx @@ -25,11 +25,6 @@ const Header = () => { key: "user_key", name: "User Name", }); - const isDarkModeEnabled = ldClient.variation( - "is-dark-mode-enabled", - user, - false, - ); const enableHighContrast = ldClient.variation( "enable-high-contrast", user, @@ -37,38 +32,18 @@ const Header = () => { ); return ( -
- {isDarkModeEnabled ? ( -
- Dark Mode is enabled. -

Welcome to a darker, more soothing interface!

- {enableHighContrast ? ( -
- High Contrast mode is enabled, enhancing visual accessibility. -
- ) : ( -
High Contrast mode is disabled.
- )} -
- ) : ( -
- Dark Mode is disabled. -

Enjoy the default light theme.

- {enableHighContrast ? ( -
- High Contrast mode is enabled, enhancing visual accessibility. -
- ) : ( -
High Contrast mode is disabled.
- )} -
- )} +
+
+ Dark Mode is enabled. +

Welcome to a darker, more soothing interface!

+ {enableHighContrast ? ( +
+ High Contrast mode is enabled, enhancing visual accessibility. +
+ ) : ( +
High Contrast mode is disabled.
+ )} +
); }; diff --git a/launchdarkly/ruby/sample.rb b/launchdarkly/ruby/sample.rb index 900c496..39d662a 100644 --- a/launchdarkly/ruby/sample.rb +++ b/launchdarkly/ruby/sample.rb @@ -17,13 +17,8 @@ module WelcomeHelper def check_feature_flags(user, ld_client) # If dark mode is enabled, check for high contrast mode - if ld_client.variation("is-dark-mode-enabled", user, false) - # Check and report the 'enable-high-contrast' feature flag for the specified user - high_contrast = ld_client.variation("enable-high-contrast", user, false) - puts "Dark mode - high contrast mode is #{high_contrast}" - else - puts "Light mode!" - end + high_contrast = ld_client.variation("enable-high-contrast", user, false) + puts "Dark mode - high contrast mode is #{high_contrast}" end def enabled_status(flag_value)