Skip to content

Commit 9308bff

Browse files
committed
Expose a configuration setting for passing a listener function
1 parent 0a4a8df commit 9308bff

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

libs/providers/go-feature-flag-web/src/lib/go-feature-flag-web-provider.ts

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export class GoFeatureFlagWebProvider implements Provider {
3838
private readonly _apiTimeout: number;
3939
// apiKey is the key used to identify your request in GO Feature Flag
4040
private readonly _apiKey: string | undefined;
41+
// listener is an optional callback triggered after successful feature flag evaluation
42+
private readonly _listener: ((key: string, value: FlagValue) => void) | undefined;
4143

4244
// initial delay in millisecond to wait before retrying to connect
4345
private readonly _retryInitialDelay;
@@ -60,6 +62,7 @@ export class GoFeatureFlagWebProvider implements Provider {
6062
this._retryDelayMultiplier = options.retryDelayMultiplier || 2;
6163
this._maxRetries = options.maxRetries || 10;
6264
this._apiKey = options.apiKey;
65+
this._listener = options.listener;
6366
}
6467

6568
get status(): ProviderStatus {
@@ -223,6 +226,9 @@ export class GoFeatureFlagWebProvider implements Provider {
223226
if (typeof resolved.value !== type) {
224227
throw new TypeMismatchError(`flag key ${flagKey} is not of type ${type}`);
225228
}
229+
230+
this._listener?.(flagKey, resolved.value);
231+
226232
return {
227233
variant: resolved.variant,
228234
value: resolved.value as T,

libs/providers/go-feature-flag-web/src/lib/model.ts

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export interface GoFeatureFlagWebProviderOptions {
5050
// maximum number of retries before considering GO Feature Flag is unreachable
5151
// Default: 10
5252
maxRetries?: number;
53+
54+
// optional callback to trigger after successful feature flag evaluation
55+
listener?: (key: string, value: FlagValue) => void;
5356
}
5457

5558
/**

0 commit comments

Comments
 (0)