Skip to content

Commit 08786a2

Browse files
committed
Use enum for stage names.
1 parent db05484 commit 08786a2

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,30 @@ import 'package:launchdarkly_dart_common/launchdarkly_dart_common.dart'
66
import '../ld_common_client.dart' show IdentifyResult, VariationMethodNames;
77
import 'hook.dart';
88

9-
const String _beforeEvaluationStageName = 'beforeEvaluation';
10-
const String _afterEvaluationStageName = 'afterEvaluation';
11-
const String _beforeIdentifyStageName = 'beforeIdentify';
12-
const String _afterIdentifyStageName = 'afterIdentify';
13-
const String _afterTrackStageName = 'afterTrack';
9+
enum HookMethodNames {
10+
beforeEvaluation('beforeEvaluation'),
11+
afterEvaluation('afterEvaluation'),
12+
beforeIdentify('beforeIdentify'),
13+
afterIdentify('afterIdentify'),
14+
afterTrack('afterTrack');
15+
16+
final String _value;
17+
18+
const HookMethodNames(this._value);
19+
20+
@override
21+
String toString() {
22+
return _value;
23+
}
24+
}
1425

1526
// Shared instance to use whenever an empty unmodifiable map is required.
1627
UnmodifiableMapView<String, LDValue> _baseData = UnmodifiableMapView({});
1728

1829
/// Safely executes a hook stage method and handles any exceptions that occur.
1930
T _tryExecuteStage<T>(
2031
LDLogger logger,
21-
String method,
32+
HookMethodNames method,
2233
String hookName,
2334
T Function() stage,
2435
T defaultValue,
@@ -44,7 +55,7 @@ List<UnmodifiableMapView<String, LDValue>> _executeBeforeEvaluation(
4455
for (final hook in hooks) {
4556
currentData = _tryExecuteStage(
4657
logger,
47-
_beforeEvaluationStageName,
58+
HookMethodNames.beforeEvaluation,
4859
hook.metadata.name,
4960
() => hook.beforeEvaluation(hookContext, currentData),
5061
currentData,
@@ -69,7 +80,7 @@ void _executeAfterEvaluation(
6980

7081
_tryExecuteStage(
7182
logger,
72-
_afterEvaluationStageName,
83+
HookMethodNames.afterEvaluation,
7384
hook.metadata.name,
7485
() => hook.afterEvaluation(hookContext, data, detail),
7586
data,
@@ -89,7 +100,7 @@ List<UnmodifiableMapView<String, LDValue>> _executeBeforeIdentify(
89100
for (final hook in hooks) {
90101
currentData = _tryExecuteStage(
91102
logger,
92-
_beforeIdentifyStageName,
103+
HookMethodNames.beforeIdentify,
93104
hook.metadata.name,
94105
() => hook.beforeIdentify(hookContext, currentData),
95106
currentData,
@@ -114,7 +125,7 @@ void _executeAfterIdentify(
114125

115126
_tryExecuteStage(
116127
logger,
117-
_afterIdentifyStageName,
128+
HookMethodNames.afterIdentify,
118129
hook.metadata.name,
119130
() => hook.afterIdentify(hookContext, data, result),
120131
data,
@@ -131,7 +142,7 @@ void _executeAfterTrack(
131142
for (final hook in hooks) {
132143
_tryExecuteStage(
133144
logger,
134-
_afterTrackStageName,
145+
HookMethodNames.afterTrack,
135146
hook.metadata.name,
136147
() => hook.afterTrack(hookContext),
137148
null,

0 commit comments

Comments
 (0)