How to use launchdarkly-js-client-sdk - 8 common examples

To help you get started, we’ve selected a few launchdarkly-js-client-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github launchdarkly / js-client-sdk / test-types.ts View on Github external
// This file exists only so that we can run the TypeScript compiler in the CI build
// to validate our typings.d.ts file. The code will not actually be run.

import * as ld from 'launchdarkly-js-client-sdk';

var ver: string = ld.version;

var emptyOptions: ld.LDOptions = {};
var logger: ld.LDLogger = ld.createConsoleLogger("info");
var allOptions: ld.LDOptions = {
  bootstrap: { },
  hash: '',
  baseUrl: '',
  eventsUrl: '',
  streamUrl: '',
  streaming: true,
  useReport: true,
  sendLDHeaders: true,
  evaluationReasons: true,
  fetchGoals: true,
  sendEvents: true,
  allAttributesPrivate: true,
  privateAttributeNames: [ 'x' ],
  allowFrequentDuplicateEvents: true,
  sendEventsOnlyForVariation: true,
github launchdarkly / js-client-sdk / test-types.ts View on Github external
// This file exists only so that we can run the TypeScript compiler in the CI build
// to validate our typings.d.ts file. The code will not actually be run.

import * as ld from 'launchdarkly-js-client-sdk';

var ver: string = ld.version;

var emptyOptions: ld.LDOptions = {};
var logger: ld.LDLogger = ld.createConsoleLogger("info");
var allOptions: ld.LDOptions = {
  bootstrap: { },
  hash: '',
  baseUrl: '',
  eventsUrl: '',
  streamUrl: '',
  streaming: true,
  useReport: true,
  sendLDHeaders: true,
  evaluationReasons: true,
  fetchGoals: true,
  sendEvents: true,
  allAttributesPrivate: true,
github yusinto / ld-redux / src / init.js View on Github external
export default ({ clientSideId, dispatch, flags, user, subscribe, options }) => {
  initFlags(flags, dispatch);

  // default subscribe to true
  const sanitisedSubscribe = typeof subscribe === 'undefined' ? true : subscribe;

  if (!user) {
    user = initUser();
  }

  window.ldClient = ldClientInitialize(clientSideId, user, options);
  window.ldClient.on('ready', () => {
    const flagsSanitised = flags || ldClient.allFlags();
    setFlags(flagsSanitised, dispatch);

    if (sanitisedSubscribe) {
      subscribeToChanges(flagsSanitised, dispatch);
    }
  });
};
github launchdarkly / js-client-sdk / test-types.ts View on Github external
email: 'test@example.com',
  avatar: 'http://avatar.url',
  ip: '1.1.1.1',
  country: 'us',
  anonymous: true,
  custom: {
    'a': 's',
    'b': true,
    'c': 3,
    'd': [ 'x', 'y' ],
    'e': [ true, false ],
    'f': [ 1, 2 ]
  },
  privateAttributeNames: [ 'name', 'email' ]
};
var client: ld.LDClient = ld.initialize('env', user, allOptions);

var boolFlagValue: ld.LDFlagValue = client.variation('key', false);
var numberFlagValue: ld.LDFlagValue = client.variation('key', 2);
var stringFlagValue: ld.LDFlagValue = client.variation('key', 'default');

var detail: ld.LDEvaluationDetail = client.variationDetail('key', 'default');
var detailValue: ld.LDFlagValue = detail.value;
var detailIndex: number | undefined = detail.variationIndex;
var detailReason: ld.LDEvaluationReason = detail.reason;

var flagSet: ld.LDFlagSet = client.allFlags();
var flagSetValue: ld.LDFlagValue = flagSet['key'];
github tdeekens / flopflip / packages / launchdarkly-adapter / modules / adapter / adapter.ts View on Github external
const initializeClient = (
  clientSideId: LaunchDarklyAdapterArgs['clientSideId'],
  user: User,
  clientOptions: LaunchDarklyAdapterArgs['clientOptions']
): LDClient =>
  initializeLaunchDarklyClient(clientSideId, user as LDUser, clientOptions);
github launchdarkly / js-client-sdk / packages / launchdarkly-react-client-sdk / src / initLDClient.ts View on Github external
const initLDClient = async (
  clientSideID: string,
  user: LDUser = { anonymous: true },
  reactOptions: LDReactOptions = defaultReactOptions,
  options?: LDOptions,
  targetFlags?: LDFlagSet,
): Promise => {
  const ldClient = ldClientInitialize(clientSideID, user, options);

  return new Promise(resolve => {
    ldClient.on('ready', () => {
      let rawFlags: LDFlagSet = {};

      if (targetFlags) {
        for (const flag in targetFlags) {
          rawFlags[flag] = ldClient.variation(flag, targetFlags[flag]);
        }
      } else {
        rawFlags = ldClient.allFlags();
      }

      const flags = reactOptions.useCamelCaseFlagKeys ? camelCaseKeys(rawFlags) : rawFlags;
      resolve({ flags, ldClient });
    });
github tdeekens / flopflip / packages / launchdarkly-adapter / modules / adapter / adapter.spec.js View on Github external
beforeEach(() => {
    onStatusStateChange = jest.fn();
    onFlagsStateChange = jest.fn();

    ldClient.initialize.mockReturnValue(createClient());
  });
github tdeekens / flopflip / packages / launchdarkly-adapter / modules / adapter / adapter.spec.js View on Github external
beforeEach(() => {
        client = createClient({
          identify: jest.fn(() => Promise.resolve()),
        });

        ldClient.initialize.mockReturnValue(client);

        return adapter.configure(
          {
            clientSideId,
            user: userWithKey,
          },
          {
            onStatusStateChange,
            onFlagsStateChange,
          }
        );
      });

launchdarkly-js-client-sdk

LaunchDarkly SDK for JavaScript

Apache-2.0
Latest version published 1 month ago

Package Health Score

86 / 100
Full package analysis