Skip to content

Commit

Permalink
docs(launch-darkly-client-provider): update README
Browse files Browse the repository at this point in the history
Add description to readme, explain new initialization.

Signed-off-by: Santiago Jimenez Giraldo <[email protected]>
  • Loading branch information
sago2k8 committed Jul 4, 2023
1 parent 5850d2d commit afaebca
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions libs/providers/launchdarkly-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,49 @@ $ npm install @openfeature/launchdarkly-client-provider
```

## Sample initialization
``` ts
// init launchdarkly-js-client-sdk
const initialContext = {
anonymous: true,
};
const ldClient = initialize('LDId', initialContext);
await ldClient.waitForInitialization();
const ldOpenFeatureProvider = new LaunchDarklyClientProvider(ldClient);

//set open feature provider and get client
OpenFeature.setProvider(ldOpenFeatureProvider);
const client = OpenFeature.getClient('my-client');

//use client
const boolValue = client.getBooleanValue('boolFlag', false);

```ts
// initialize provider
const clientEnvKey = 'LDEnvironmentID';

/*
* optional launch darkly options
* @see https://launchdarkly.github.io/js-client-sdk/interfaces/LDOptions.html
*/
const ldOptions = {
straming: true,
};

/*
* initialization happens inside the provider, the initial context will be { anonymous: true } by default, this is done for simplicity,
* @see https://launchdarkly.github.io/js-client-sdk/interfaces/LDContextCommon.html#anonymous
* you can change it using setContext.
*/
const ldOpenFeatureProvider = new LaunchDarklyClientProvider(clientEnvKey, options);

//set open feature provider and get client
OpenFeature.setProvider(ldOpenFeatureProvider);
const client = OpenFeature.getClient('my-client');

//use client
const boolValue = client.getBooleanValue('boolFlag', false);
```

## Update Context
For context update always use ``OpenFeature.setContext(myNewContext);`` instead of ``ldClient.identify(myNewContext);``, as this will always be handled internally.

For context update always use `OpenFeature.setContext(myNewContext);`

Please note that context changes result in network traffic, so changes should be made sparingly in accordance to relevant user behavior.
``` ts
await OpenFeature.setContext({ targetingKey: 'my-key' })
//Laundarkly uses key but this provider tranlates targetingKey to key;
//So the above is the same as doing
await OpenFeature.setContext({ key: 'my-key' });

```ts
await OpenFeature.setContext({ targetingKey: 'my-key' });
//Laundarkly uses key but this provider tranlates targetingKey to key;
//So the above is the same as doing
await OpenFeature.setContext({ key: 'my-key' });
```

Read more about LD contexts [here](https://github.com/launchdarkly/openfeature-node-server#openfeature-specific-considerations)
Read more about LD contexts [here](https://launchdarkly.github.io/js-client-sdk/interfaces/LDContextCommon.html)

## Building

Expand Down

0 comments on commit afaebca

Please sign in to comment.