Skip to content

Commit e160fb1

Browse files
committed
Make metadata abstract.
1 parent 9b85755 commit e160fb1

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

packages/common_client/lib/src/hooks/hook.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,22 @@ final class TrackSeriesContext {
7878
///
7979
/// Default implementations are provided for each stage and an implementer
8080
/// should override at least one of the stage methods.
81-
base class Hook {
82-
final HookMetadata metadata;
81+
///
82+
/// All implementations must implement the metadata getter.
83+
abstract base class Hook {
84+
/// Metadata associated with this hook.
85+
///
86+
/// Hook implementations must implement this property.
87+
/// ```dart
88+
/// final _metadata = HookMetadata(name: 'MyHookName');
89+
///
90+
/// @override
91+
/// HookMetadata get metadata => _metadata;
92+
/// ```
93+
HookMetadata get metadata;
8394

8495
/// Construct a new hook instance.
85-
Hook(this.metadata);
96+
Hook();
8697

8798
/// This method is called during the execution of a variation method before
8899
/// the flag value has been determined. The method is executed synchronously.

packages/common_client/test/hooks/hook_runner_test.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ final class TestHook extends Hook {
1616
final String? errorMessage;
1717
final List<UnmodifiableMapView<String, LDValue>> receivedBeforeData = [];
1818
final List<UnmodifiableMapView<String, LDValue>> receivedAfterData = [];
19+
final HookMetadata _metadata;
1920

2021
// For tracking execution order across multiple hooks
2122
static final List<String> globalExecutionOrder = [];
2223

24+
@override
25+
HookMetadata get metadata => _metadata;
26+
2327
TestHook({
2428
required String name,
2529
this.dataToReturn = const {},
2630
this.shouldThrow = false,
2731
this.errorMessage,
28-
}) : super(HookMetadata(name: name));
32+
}) : _metadata = HookMetadata(name: name),
33+
super();
2934

3035
void clearGlobalOrder() {
3136
globalExecutionOrder.clear();

packages/common_client/test/hooks/ld_common_client_hooks_test.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ final class TestHook extends Hook {
1111
final List<TrackSeriesContext> trackContexts = [];
1212
final List<IdentifyResult> identifyResults = [];
1313
final List<LDEvaluationDetail<LDValue>> evaluationResults = [];
14+
final HookMetadata _metadata;
1415

15-
TestHook(String name) : super(HookMetadata(name: name));
16+
@override
17+
HookMetadata get metadata => _metadata;
18+
19+
TestHook(String name)
20+
: _metadata = HookMetadata(name: name),
21+
super();
1622

1723
@override
1824
UnmodifiableMapView<String, LDValue> beforeEvaluation(

0 commit comments

Comments
 (0)