Skip to content

Commit

Permalink
Expose a configuration setting for passing a listener function
Browse files Browse the repository at this point in the history
  • Loading branch information
mbezhanov committed Jun 20, 2024
1 parent 0a4a8df commit 9308bff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class GoFeatureFlagWebProvider implements Provider {
private readonly _apiTimeout: number;
// apiKey is the key used to identify your request in GO Feature Flag
private readonly _apiKey: string | undefined;
// listener is an optional callback triggered after successful feature flag evaluation
private readonly _listener: ((key: string, value: FlagValue) => void) | undefined;

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

get status(): ProviderStatus {
Expand Down Expand Up @@ -223,6 +226,9 @@ export class GoFeatureFlagWebProvider implements Provider {
if (typeof resolved.value !== type) {
throw new TypeMismatchError(`flag key ${flagKey} is not of type ${type}`);
}

this._listener?.(flagKey, resolved.value);

return {
variant: resolved.variant,
value: resolved.value as T,
Expand Down
3 changes: 3 additions & 0 deletions libs/providers/go-feature-flag-web/src/lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export interface GoFeatureFlagWebProviderOptions {
// maximum number of retries before considering GO Feature Flag is unreachable
// Default: 10
maxRetries?: number;

// optional callback to trigger after successful feature flag evaluation
listener?: (key: string, value: FlagValue) => void;
}

/**
Expand Down

0 comments on commit 9308bff

Please sign in to comment.