Skip to content

Commit f52d8c5

Browse files
committed
evaluate prereqs in client
1 parent 5e26257 commit f52d8c5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

libs/client-sdk/src/client_impl.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,26 @@ EvaluationDetail<T> ClientImpl::VariationInternal(FlagKey const& key,
305305
auto const& flag = *(desc->item);
306306
auto const& detail = flag.Detail();
307307

308+
// The Prerequisites vector represents the evaluated prerequisites of
309+
// this flag. We need to generate events for both this flag and its
310+
// prerequisites (recursively), which is necessary to ensure LaunchDarkly
311+
// analytics functions properly.
312+
//
313+
// We're using JsonVariation because the type of the
314+
// prerequisite is both unknown and irrelevant to emitting the events.
315+
//
316+
// We're passing Value::Null() to match a server-side SDK's behavior when
317+
// evaluating prerequisites.
318+
//
319+
// NOTE: if "hooks" functionality is implemented into this SDK, take care
320+
// that evaluating prerequisites does not trigger hooks. This may require
321+
// refactoring the code below to not use JsonVariation.
322+
if (auto const prereqs = flag.Prerequisites()) {
323+
for (auto const& prereq : *prereqs) {
324+
JsonVariation(prereq, Value::Null());
325+
}
326+
}
327+
308328
if (check_type && default_value.Type() != Value::Type::kNull &&
309329
detail.Value().Type() != default_value.Type()) {
310330
auto error_reason =

0 commit comments

Comments
 (0)