Skip to content

Commit

Permalink
cleanup readme and example
Browse files Browse the repository at this point in the history
  • Loading branch information
atrakh committed Oct 28, 2024
1 parent 357943e commit a8793e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ const launchdarkly = new LaunchDarkly(components.launchdarkly);
export const myQuery = query({
args: {},
handler: async ({ ctx }) => {
const launchdarkly = ld.sdk(ctx);
const isFlagOn = await launchdarkly.boolVariation(
const ld = launchdarkly.sdk(ctx);
const isFlagOn = await ld.boolVariation(
"my-flag",
{ key: "myUser" },
false
Expand Down Expand Up @@ -204,20 +204,20 @@ Once configured, you may initialize `LaunchDarkly` with the appropriate componen
```typescript
import { LaunchDarkly } from "@convex-dev/launchdarkly";

const ldFirst = new LaunchDarkly(components.first, {
const launchDarklyFirst = new LaunchDarkly(components.first, {
LAUNCHDARKLY_SDK_KEY: process.env.LAUNCHDARKLY_SDK_KEY_FIRST!,
});

const ldSecond = new LaunchDarkly(components.second, {
const launchDarklySecond = new LaunchDarkly(components.second, {
LAUNCHDARKLY_SDK_KEY: process.env.LAUNCHDARKLY_SDK_KEY_SECOND!,
});

export const myQuery = query({
args: {},
handler: async ({ ctx }) => {
const launchdarklyFirst = ldFirst.sdk(ctx);
const ldFirst = launchdarklyFirst.sdk(ctx);

const launchdarklySecond = ldSecond.sdk(ctx);
const ldSecond = launchDarklySecond.sdk(ctx);

...
},
Expand Down
19 changes: 5 additions & 14 deletions example/convex/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ const launchdarkly = new LaunchDarkly(components.launchdarkly);

export const listFruits = query({
handler: async (ctx) => {
const ld= = launchdarkly.sdk(ctx);
const ld = launchdarkly.sdk(ctx);
const user = { key: "myUserId" };

const showFruits = await ld.boolVariation(
"can-show-fruits",
user,
true
);
const showFruits = await ld.boolVariation("can-show-fruits", user, true);
if (!showFruits) {
return [];
}
Expand All @@ -27,11 +23,7 @@ export const buyFruit = mutation({

const user = { key: "myUserId" };

const showFruits = await ld.boolVariation(
"can-buy-fruits",
user,
false
);
const showFruits = await ld.boolVariation("can-buy-fruits", user, false);
if (!showFruits) {
return {
error:
Expand All @@ -51,9 +43,8 @@ export const initialized = query({
}
const ld = launchdarkly.sdk(ctx);
return (
(await ld.allFlagsState({ key: "any" })).allValues()[
"can-buy-fruits"
] !== undefined
(await ld.allFlagsState({ key: "any" })).allValues()["can-buy-fruits"] !==
undefined
);
},
});
Expand Down

0 comments on commit a8793e9

Please sign in to comment.