Skip to content
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

Find context attribute #4

Open
shanman190 opened this issue Aug 23, 2023 · 0 comments
Open

Find context attribute #4

shanman190 opened this issue Aug 23, 2023 · 0 comments
Labels

Comments

@shanman190
Copy link
Collaborator

shanman190 commented Aug 23, 2023

Parameters:

  • Attribute key (optional)
  • Attribute value (optional)

Built-in attribute

Before:

import com.launchdarkly.sdk.LDContext;
import com.launchdarkly.sdk.server.LDClient;

class Test {
    public void a() {
        LDClient client = new LDClient("sdk-key");
        LDContext context = LDContext.builder("context-key")
                .name("user")
                .build();
        boolean flagValue = client.boolVariation("flag-key-123abc", context, false);
        if (flagValue) {
            // Application code to show the feature
        } else {
            // The code to run if the feature is off
        }
    }
}

After:

import com.launchdarkly.sdk.LDContext;
import com.launchdarkly.sdk.server.LDClient;

class Test {
    public void a() {
        LDClient client = new LDClient("sdk-key");
        LDContext context = LDContext.builder("context-key")
                /*~~>*/.name("user")
                .build();
        boolean flagValue = client.boolVariation("flag-key-123abc", context, false);
        if (flagValue) {
            // Application code to show the feature
        } else {
            // The code to run if the feature is off
        }
    }
}

Custom Attribute

Before:

import com.launchdarkly.sdk.LDContext;
import com.launchdarkly.sdk.server.LDClient;

class Test {
    public void a() {
        LDClient client = new LDClient("sdk-key");
        LDContext context = LDContext.builder("context-key")
                .name("user")
                .set("email", "[email protected]")
                .build();
        boolean flagValue = client.boolVariation("flag-key-123abc", context, false);
        if (flagValue) {
            // Application code to show the feature
        } else {
            // The code to run if the feature is off
        }
    }
}

After:

import com.launchdarkly.sdk.LDContext;
import com.launchdarkly.sdk.server.LDClient;

class Test {
    public void a() {
        LDClient client = new LDClient("sdk-key");
        LDContext context = LDContext.builder("context-key")
                .name("user")
                /*~~>*/.set("email", "[email protected]")
                .build();
        boolean flagValue = client.boolVariation("flag-key-123abc", context, false);
        if (flagValue) {
            // Application code to show the feature
        } else {
            // The code to run if the feature is off
        }
    }
}
@timtebeek timtebeek moved this to Recipes Wanted in OpenRewrite Aug 23, 2023
@shanman190 shanman190 changed the title Find context attribute Find context attribute key Aug 23, 2023
@shanman190 shanman190 changed the title Find context attribute key Find context attribute Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Recipes Wanted
Development

No branches or pull requests

2 participants