You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Multi-Provider comes with three strategies out of the box:
70
-
`FirstMatchStrategy` (default): Evaluates all providers in order and returns the first successful result. Providers that indicate FLAG_NOT_FOUND error will be skipped and the next provider will be evaluated. Any other error will cause the operation to fail and the set of errors to be thrown.
65
+
66
+
-`FirstMatchStrategy` (default): Evaluates all providers in order and returns the first successful result. Providers that indicate FLAG_NOT_FOUND error will be skipped and the next provider will be evaluated. Any other error will cause the operation to fail and the set of errors to be thrown.
71
67
-`FirstSuccessfulStrategy`: Evaluates all providers in order and returns the first successful result. Any error will cause that provider to be skipped.
72
68
If no successful result is returned, the set of errors will be thrown.
73
69
-`ComparisonStrategy`: Evaluates all providers in parallel. If every provider returns a successful result with the same value, then that result is returned.
The first argument is the "fallback provider" whose value to use in the event that providers do not agree. It should be the same object reference as one of the providers in the list. The second argument is a callback function that will be executed when a mismatch is detected. The callback will be passed an object containing the details of each provider's resolution, including the flag key, the value returned, and any errors that were thrown.
99
92
100
93
## Custom Strategies
94
+
101
95
It is also possible to implement your own strategy if the above options do not fit your use case. To do so, create a class which implements the "BaseEvaluationStrategy":
96
+
102
97
```typescript
103
98
exportabstractclassBaseEvaluationStrategy {
104
99
public runMode:'parallel'|'sequential'='sequential';
@@ -111,13 +106,21 @@ export abstract class BaseEvaluationStrategy {
111
106
result:ProviderResolutionResult<T>,
112
107
):boolean;
113
108
109
+
abstract shouldTrackWithThisProvider(
110
+
strategyContext:StrategyProviderContext,
111
+
context:EvaluationContext,
112
+
trackingEventName:string,
113
+
trackingEventDetails:TrackingEventDetails,
114
+
):boolean;
115
+
114
116
abstract determineFinalResult<TextendsFlagValue>(
115
117
strategyContext:StrategyEvaluationContext,
116
118
context:EvaluationContext,
117
119
resolutions:ProviderResolutionResult<T>[],
118
120
):FinalResult<T>;
119
121
}
120
122
```
123
+
121
124
The `runMode` property determines whether the list of providers will be evaluated sequentially or in parallel.
122
125
123
126
The `shouldEvaluateThisProvider` method is called just before a provider is evaluated by the Multi-Provider. If the function returns `false`, then
@@ -127,9 +130,81 @@ Check the type definitions for the full list.
127
130
The `shouldEvaluateNextProvider` function is called after a provider is evaluated. If it returns `true`, the next provider in the sequence will be called,
128
131
otherwise no more providers will be evaluated. It is called with the same data as `shouldEvaluateThisProvider` as well as the details about the evaluation result. This function is not called when the `runMode` is `parallel`.
129
132
133
+
The `shouldTrackWithThisProvider` method is called before tracking an event with each provider. If the function returns `false`, then
134
+
the provider will be skipped for that tracking event. The method includes the tracking event name and details,
135
+
allowing for fine-grained control over which providers receive which events. By default, providers in `NOT_READY` or `FATAL` status are skipped.
136
+
130
137
The `determineFinalResult` function is called after all providers have been called, or the `shouldEvaluateNextProvider` function returned false. It is called
131
138
with a list of results from all the individual providers' evaluations. It returns the final decision for evaluation result, or throws an error if needed.
132
139
140
+
## Tracking Support
141
+
142
+
The Multi-Provider supports tracking events across multiple providers, allowing you to send analytics events to all configured providers simultaneously.
0 commit comments