Skip to content

[Gitar] Cleaning up stale flag: is-dark-mode-enabled with value true #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
35 changes: 35 additions & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Repository Summary

## Purpose
This repository provides examples of LaunchDarkly feature flag implementation across multiple programming languages and frameworks. It demonstrates how to initialize, query, and respond to feature flags in different environments.

## Languages and Frameworks
The repository includes LaunchDarkly feature flag implementation examples for:
- Go
- React/TypeScript
- Java
- Kotlin
- Ruby
- Node.js
- Dart

## Repository Structure
The codebase is organized by language, with each language subdirectory containing sample code that demonstrates:
- LaunchDarkly client initialization
- Feature flag queries
- Conditional logic based on flag values
- Error handling and fallback strategies

## Feature Flag Usage Pattern
Across all language examples, the code demonstrates a common pattern:
1. Initialize the LaunchDarkly client with appropriate configuration
2. Create a user context for personalized flag evaluation
3. Query specific feature flags (e.g., "enable-high-contrast")
4. Implement conditional logic based on flag values
5. Handle potential errors with fallback strategies

## Purpose of Examples
These examples serve as reference implementations to help developers:
- Understand proper LaunchDarkly SDK usage
- Implement feature flags consistently across different technologies
- Follow best practices for feature flag management and cleanup
16 changes: 2 additions & 14 deletions launchdarkly/dart/sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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("Now dark mode is on!");

await ldClient.close();
}
Expand Down
24 changes: 8 additions & 16 deletions launchdarkly/go/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
17 changes: 2 additions & 15 deletions launchdarkly/java/Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}

}
26 changes: 3 additions & 23 deletions launchdarkly/java/SampleDeep.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,8 @@ class SampleDeep {

public void sampleMethodCheckingFlag(Map<String, String> 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<String, String> config) {
return config.get("dark-mode").equals("on");
}

}
16 changes: 5 additions & 11 deletions launchdarkly/kotlin/sample.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
Expand Down
18 changes: 1 addition & 17 deletions launchdarkly/node/sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,8 @@
import * as LaunchDarkly from "@launchdarkly/node-server-sdk";

const SDK_KEY = "<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");
});
49 changes: 12 additions & 37 deletions launchdarkly/react/sample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,25 @@ 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,
true,
);

return (
<div
style={
isDarkModeEnabled
? { backgroundColor: "#333", color: "#fff" }
: { backgroundColor: "#fff", color: "#000" }
}
>
{isDarkModeEnabled ? (
<div>
Dark Mode is enabled.
<p>Welcome to a darker, more soothing interface!</p>
{enableHighContrast ? (
<div>
High Contrast mode is enabled, enhancing visual accessibility.
</div>
) : (
<div>High Contrast mode is disabled.</div>
)}
</div>
) : (
<div>
Dark Mode is disabled.
<p>Enjoy the default light theme.</p>
{enableHighContrast ? (
<div>
High Contrast mode is enabled, enhancing visual accessibility.
</div>
) : (
<div>High Contrast mode is disabled.</div>
)}
</div>
)}
<div style={{ backgroundColor: "#333", color: "#fff" }}>
<div>
Dark Mode is enabled.
<p>Welcome to a darker, more soothing interface!</p>
{enableHighContrast ? (
<div>
High Contrast mode is enabled, enhancing visual accessibility.
</div>
) : (
<div>High Contrast mode is disabled.</div>
)}
</div>
</div>
);
};
Expand Down
9 changes: 2 additions & 7 deletions launchdarkly/ruby/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down