From 5bba5efc64c3ac6b7668fbee4ec7e586bbbe31d3 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Mon, 11 Sep 2023 08:51:47 -0700 Subject: [PATCH 1/2] chore: Add docs for emitted events. --- packages/sdk/server-node/src/api/LDClient.ts | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/sdk/server-node/src/api/LDClient.ts b/packages/sdk/server-node/src/api/LDClient.ts index a2db766275..3f0f0eecc7 100644 --- a/packages/sdk/server-node/src/api/LDClient.ts +++ b/packages/sdk/server-node/src/api/LDClient.ts @@ -21,4 +21,29 @@ export interface LDClient extends LDClientCommon, EventEmitter { * {@link interfaces.BigSegmentStoreStatusProvider} for more about this functionality. */ readonly bigSegmentStoreStatusProvider: BigSegmentStoreStatusProvider; + + /** + * Registers an event listener that will be called when the client triggers some type of event. + * + * This is the standard `on` method inherited from Node's `EventEmitter`; see the + * {@link https://nodejs.org/api/events.html#events_class_eventemitter|Node API docs} for more + * details on how to manage event listeners. Here is a description of the event types defined + * by `LDClient`. + * + * - `"ready"`: Sent only once, when the client has successfully connected to LaunchDarkly. + * Alternately, you can detect this with [[waitForInitialization]]. + * - `"failed"`: Sent only once, if the client has permanently failed to connect to LaunchDarkly. + * Alternately, you can detect this with [[waitForInitialization]]. + * - `"error"`: Contains an error object describing some abnormal condition that the client has detected + * (such as a network error). + * - `"update"`: The client has received a change to a feature flag. The event parameter is an object + * containing a single property, `key`, the flag key. Note that this does not necessarily mean the flag's + * value has changed for any particular context, only that some part of the flag configuration was changed. + * - `"update:KEY"`: The client has received a change to the feature flag whose key is KEY. This is the + * same as `"update"` but allows you to listen for a specific flag. + * + * @param event the name of the event to listen for + * @param listener the function to call when the event happens + */ + on(event: string | symbol, listener: (...args: any[]) => void): this; } From 98b0e5ac8279616de2299f85f988e4584a4cdeac Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Mon, 11 Sep 2023 09:20:44 -0700 Subject: [PATCH 2/2] Extend docs --- packages/sdk/server-node/src/api/LDClient.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/sdk/server-node/src/api/LDClient.ts b/packages/sdk/server-node/src/api/LDClient.ts index 3f0f0eecc7..67810a88ff 100644 --- a/packages/sdk/server-node/src/api/LDClient.ts +++ b/packages/sdk/server-node/src/api/LDClient.ts @@ -11,6 +11,11 @@ import { BigSegmentStoreStatusProvider } from './interfaces'; * and continue to use it throughout the lifetime of the application, rather than creating instances * on the fly. * + * Note that `LDClient` inherits from `EventEmitter`, so you can use the standard `on()`, `once()`, and + * `off()` methods to receive events. The standard `EventEmitter` methods are not documented here; see the + * {@link https://nodejs.org/api/events.html#events_class_eventemitter|Node API documentation}. For a + * description of events you can listen for, see {@link on}. + * */ export interface LDClient extends LDClientCommon, EventEmitter { /** @@ -23,6 +28,7 @@ export interface LDClient extends LDClientCommon, EventEmitter { readonly bigSegmentStoreStatusProvider: BigSegmentStoreStatusProvider; /** + * * Registers an event listener that will be called when the client triggers some type of event. * * This is the standard `on` method inherited from Node's `EventEmitter`; see the