ReadonlyloggerThe logger configured as part of LDOptions during construction.
For more information, read LDOptions.logger and LDLogger.
The configured LDLogger.
Returns a map of all available flags to the current context's values.
An object in which each key is a feature flag key and each value is the flag value. Note that there is no way to specify a default value for each flag as there is with variation, so any flag that cannot be evaluated will be undefined.
Determines the boolean variation of a feature flag.
If the flag variation does not have a boolean value, defaultValue is returned.
The unique key of the feature flag.
The default value of the flag, to be used if the value is not available from LaunchDarkly.
The boolean value.
Determines the boolean variation of a feature flag, along with information about how it was calculated.
The reason property of the result will also be included in analytics events, if you are
capturing detailed event data for this flag.
If the flag variation does not have a boolean value, defaultValue is returned. The reason will
indicate an error of the type WRONG_KIND in this case.
For more information, see the SDK reference guide.
The unique key of the feature flag.
The default value of the flag, to be used if the value is not available from LaunchDarkly.
Shuts down the client and releases its resources, after delivering any pending analytics events.
Flushes all pending analytics events.
Normally, batches of events are delivered in the background at intervals determined by the
flushInterval property of LDOptions. Calling flush() triggers an immediate delivery.
A Promise which resolves once flushing is finished. You can inspect the result of the flush for errors.
Identifies a context to LaunchDarkly.
Unlike the server-side SDKs, the client-side JavaScript SDKs maintain a current context state,
which is set when you call identify().
Changing the current context also causes all feature flag values to be reloaded. Until that has finished, calls to variation will still return flag values for the previous context. You can await the Promise to determine when the new flag values are available.
If used with the sheddable option set to true, then the identify operation will be sheddable. This means that if
multiple identify operations are done, without waiting for the previous one to complete, then intermediate
operations may be discarded.
The LDContext object.
OptionalidentifyOptions: LDIdentifyOptions
Optional configuration. Please see LDIdentifyOptions.
A Promise which resolves when the flag values for the specified context are available. It rejects when:
The context is unspecified or has no key.
The identify timeout is exceeded. In client SDKs this defaults to 5s. You can customize this timeout with identifyOptions.
A network error is encountered during initialization.
Determines the json variation of a feature flag.
This version may be favored in TypeScript versus variation because it returns
an unknown type instead of any. unknown will require a cast before usage.
The unique key of the feature flag.
The default value of the flag, to be used if the value is not available from LaunchDarkly.
The json value.
Determines the json variation of a feature flag, along with information about how it was calculated.
The reason property of the result will also be included in analytics events, if you are
capturing detailed event data for this flag.
This version may be favored in TypeScript versus variation because it returns
an unknown type instead of any. unknown will require a cast before usage.
For more information, see the SDK reference guide.
The unique key of the feature flag.
The default value of the flag, to be used if the value is not available from LaunchDarkly.
Determines the numeric variation of a feature flag.
If the flag variation does not have a numeric value, defaultValue is returned.
The unique key of the feature flag.
The default value of the flag, to be used if the value is not available from LaunchDarkly.
The numeric value.
Determines the numeric variation of a feature flag for a context, along with information about how it was calculated.
The unique key of the feature flag.
The default value of the flag, to be used if the value is not available from LaunchDarkly.
The reason property of the result will also be included in analytics events, if you are
capturing detailed event data for this flag.
If the flag variation does not have a numeric value, defaultValue is returned. The reason will
indicate an error of the type WRONG_KIND in this case.
For more information, see the SDK reference guide.
Removes an event listener. See on for the available event types.
The name of the event for which to stop listening.
The function to deregister.
Registers an event listener.
The name of the event for which to listen.
The function to execute when the event fires. The callback may or may not receive parameters, depending on the type of event.
You can subscribe to one of the supported EventName:
"change": The client has received new feature flag data. This can happen either
because you have switched contexts with identify, or because the client has a
stream connection and has received a live change to a flag value (see below).
The callback parameters are the context and an array of flag keys that have changed.
"error": General event for any kind of error condition during client operation.
The callback parameters are the context and an Error object. Errors are also output by
the logger at the error level.
"dataSourceStatus": Event indicating that there has been a change in the status of the
data source. This will include the state of the data source as well any error information.
Determines the string variation of a feature flag.
If the flag variation does not have a string value, defaultValue is returned.
The unique key of the feature flag.
The default value of the flag, to be used if the value is not available from LaunchDarkly.
The string value.
Determines the string variation of a feature flag for a context, along with information about how it was calculated.
The unique key of the feature flag.
The default value of the flag, to be used if the value is not available from LaunchDarkly.
The reason property of the result will also be included in analytics events, if you are
capturing detailed event data for this flag.
If the flag variation does not have a string value, defaultValue is returned. The reason will
indicate an error of the type WRONG_KIND in this case.
For more information, see the SDK reference guide.
Track events for experiments.
The name of the event, which may correspond to a goal in an experiment.
Optionaldata: any
Additional information to associate with the event.
OptionalmetricValue: number
An optional numeric value that can be used by the LaunchDarkly experimentation feature in numeric custom metrics. Can be omitted if this event is used by only non-numeric metrics. This field will also be returned as part of the custom event for Data Export.
We recommend using strongly typed variation methods which perform type checks and handle type errors.
The unique key of the feature flag.
OptionaldefaultValue: any
The default value of the flag, to be used if the value is not available from LaunchDarkly.
The flag's value.
We recommend using strongly typed variation detail methods which perform type checks and handle type errors.
The unique key of the feature flag.
OptionaldefaultValue: any
The default value of the flag, to be used if the value is not available from LaunchDarkly.
An LDEvaluationDetail object containing the value and explanation.
Determines the variation of a feature flag for a context, along with information about how it was calculated.
Note that this will only work if you have set withReasons to true in LDOptions.
The reason property of the result will also be included in analytics events, if you are
capturing detailed event data for this flag.
For more information, see the SDK reference guide.
Returns a Promise that tracks the client's initialization state.
The Promise will be resolved to a LDWaitForInitializationResult object containing the status of the waitForInitialization operation.
Optionaloptions: LDWaitForInitializationOptions
Optional configuration. Please see LDWaitForInitializationOptions.
A Promise that will be resolved to a LDWaitForInitializationResult object containing the status of the waitForInitialization operation.
This example shows use of async/await syntax for specifying handlers:
const result = await client.waitForInitialization({ timeout: 5 });
if (result.status === 'complete') {
doSomethingWithSuccessfullyInitializedClient();
} else if (result.status === 'failed') {
doSomethingForFailedStartup(result.error);
} else if (result.status === 'timeout') {
doSomethingForTimedOutStartup();
}
You can also use event listeners (on) for the same purpose: the event "initialized"
indicates success, and "error" indicates an error.
The basic interface for the LaunchDarkly client. Platform-specific SDKs may add some methods of their own.
See
https://docs.launchdarkly.com/sdk/client-side/javascript