Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add docs for emitted events. #273

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/sdk/server-node/src/api/LDClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -21,4 +26,30 @@ 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;
}