Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions packages/common_client/lib/src/hooks/hook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ abstract base class Hook {
/// newData['new-key'] = LDValue.ofString('new-value');
/// return UnmodifiableMapView(newData);
/// ```
UnmodifiableMapView<String, LDValue> beforeEvaluation(
UnmodifiableMapView<String, dynamic> beforeEvaluation(
EvaluationSeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data) {
UnmodifiableMapView<String, dynamic> data) {
return data;
}

Expand All @@ -162,9 +162,9 @@ abstract base class Hook {
/// newData['new-key'] = LDValue.ofString('new-value');
/// return UnmodifiableMapView(newData);
/// ```
UnmodifiableMapView<String, LDValue> afterEvaluation(
UnmodifiableMapView<String, dynamic> afterEvaluation(
EvaluationSeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data,
UnmodifiableMapView<String, dynamic> data,
LDEvaluationDetail<LDValue> detail) {
return data;
}
Expand All @@ -188,9 +188,9 @@ abstract base class Hook {
/// newData['new-key'] = LDValue.ofString('new-value');
/// return UnmodifiableMapView(newData);
/// ```
UnmodifiableMapView<String, LDValue> beforeIdentify(
UnmodifiableMapView<String, dynamic> beforeIdentify(
IdentifySeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data) {
UnmodifiableMapView<String, dynamic> data) {
return data;
}

Expand All @@ -210,12 +210,12 @@ abstract base class Hook {
///
/// ```dart
/// Map<String, LDValue> newData = Map.from(data);
/// newData['new-key'] = LDValue.ofString('new-value');
/// newData['new-key'] = 'new-value';
/// return UnmodifiableMapView(newData);
/// ```
UnmodifiableMapView<String, LDValue> afterIdentify(
UnmodifiableMapView<String, dynamic> afterIdentify(
IdentifySeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data,
UnmodifiableMapView<String, dynamic> data,
IdentifyResult result) {
return data;
}
Expand Down
18 changes: 9 additions & 9 deletions packages/common_client/lib/src/hooks/hook_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum HookMethodNames {
}

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

/// Safely executes a hook stage method and handles any exceptions that occur.
T _tryExecuteStage<T>(
Expand All @@ -44,13 +44,13 @@ T _tryExecuteStage<T>(
}

/// Executes the beforeEvaluation stage for all hooks.
List<UnmodifiableMapView<String, LDValue>> _executeBeforeEvaluation(
List<UnmodifiableMapView<String, dynamic>> _executeBeforeEvaluation(
LDLogger logger,
List<Hook> hooks,
EvaluationSeriesContext hookContext,
) {
final results = <UnmodifiableMapView<String, LDValue>>[];
UnmodifiableMapView<String, LDValue> currentData = _baseData;
final results = <UnmodifiableMapView<String, dynamic>>[];
UnmodifiableMapView<String, dynamic> currentData = _baseData;

for (final hook in hooks) {
currentData = _tryExecuteStage(
Expand All @@ -71,7 +71,7 @@ void _executeAfterEvaluation(
LDLogger logger,
List<Hook> hooks,
EvaluationSeriesContext hookContext,
List<UnmodifiableMapView<String, LDValue>> hookData,
List<UnmodifiableMapView<String, dynamic>> hookData,
LDEvaluationDetail<LDValue> detail,
) {
for (int i = hooks.length - 1; i >= 0; i--) {
Expand All @@ -89,13 +89,13 @@ void _executeAfterEvaluation(
}

/// Executes the beforeIdentify stage for all hooks.
List<UnmodifiableMapView<String, LDValue>> _executeBeforeIdentify(
List<UnmodifiableMapView<String, dynamic>> _executeBeforeIdentify(
LDLogger logger,
List<Hook> hooks,
IdentifySeriesContext hookContext,
) {
final results = <UnmodifiableMapView<String, LDValue>>[];
UnmodifiableMapView<String, LDValue> currentData = _baseData;
final results = <UnmodifiableMapView<String, dynamic>>[];
UnmodifiableMapView<String, dynamic> currentData = _baseData;

for (final hook in hooks) {
currentData = _tryExecuteStage(
Expand All @@ -116,7 +116,7 @@ void _executeAfterIdentify(
LDLogger logger,
List<Hook> hooks,
IdentifySeriesContext hookContext,
List<UnmodifiableMapView<String, LDValue>> hookData,
List<UnmodifiableMapView<String, dynamic>> hookData,
IdentifyResult result,
) {
for (int i = hooks.length - 1; i >= 0; i--) {
Expand Down
26 changes: 13 additions & 13 deletions packages/common_client/test/hooks/hook_runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class MockLogAdapter extends Mock implements LDLogAdapter {}

final class TestHook extends Hook {
final List<String> callLog = [];
final Map<String, LDValue> dataToReturn;
final Map<String, dynamic> dataToReturn;
final bool shouldThrow;
final String? errorMessage;
final List<UnmodifiableMapView<String, LDValue>> receivedBeforeData = [];
final List<UnmodifiableMapView<String, LDValue>> receivedAfterData = [];
final List<UnmodifiableMapView<String, dynamic>> receivedBeforeData = [];
final List<UnmodifiableMapView<String, dynamic>> receivedAfterData = [];
final HookMetadata _metadata;

// For tracking execution order across multiple hooks
Expand All @@ -37,25 +37,25 @@ final class TestHook extends Hook {
}

@override
UnmodifiableMapView<String, LDValue> beforeEvaluation(
UnmodifiableMapView<String, dynamic> beforeEvaluation(
EvaluationSeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data,
UnmodifiableMapView<String, dynamic> data,
) {
if (shouldThrow) {
throw Exception(errorMessage ?? 'Test error in beforeEvaluation');
}
callLog.add('beforeEvaluation');
globalExecutionOrder.add('${metadata.name}-before');
receivedBeforeData.add(data);
final newData = Map<String, LDValue>.from(data);
final newData = Map<String, dynamic>.from(data);
newData.addAll(dataToReturn);
return UnmodifiableMapView(newData);
}

@override
UnmodifiableMapView<String, LDValue> afterEvaluation(
UnmodifiableMapView<String, dynamic> afterEvaluation(
EvaluationSeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data,
UnmodifiableMapView<String, dynamic> data,
LDEvaluationDetail<LDValue> detail,
) {
if (shouldThrow) {
Expand All @@ -68,24 +68,24 @@ final class TestHook extends Hook {
}

@override
UnmodifiableMapView<String, LDValue> beforeIdentify(
UnmodifiableMapView<String, dynamic> beforeIdentify(
IdentifySeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data,
UnmodifiableMapView<String, dynamic> data,
) {
if (shouldThrow) {
throw Exception(errorMessage ?? 'Test error in beforeIdentify');
}
callLog.add('beforeIdentify');
globalExecutionOrder.add('${metadata.name}-beforeIdentify');
final newData = Map<String, LDValue>.from(data);
final newData = Map<String, dynamic>.from(data);
newData.addAll(dataToReturn);
return UnmodifiableMapView(newData);
}

@override
UnmodifiableMapView<String, LDValue> afterIdentify(
UnmodifiableMapView<String, dynamic> afterIdentify(
IdentifySeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data,
UnmodifiableMapView<String, dynamic> data,
IdentifyResult result,
) {
if (shouldThrow) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ final class TestHook extends Hook {
super();

@override
UnmodifiableMapView<String, LDValue> beforeEvaluation(
UnmodifiableMapView<String, dynamic> beforeEvaluation(
EvaluationSeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data,
UnmodifiableMapView<String, dynamic> data,
) {
callLog.add('beforeEvaluation');
evaluationContexts.add(hookContext);
return data;
}

@override
UnmodifiableMapView<String, LDValue> afterEvaluation(
UnmodifiableMapView<String, dynamic> afterEvaluation(
EvaluationSeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data,
UnmodifiableMapView<String, dynamic> data,
LDEvaluationDetail<LDValue> detail,
) {
callLog.add('afterEvaluation');
Expand All @@ -45,19 +45,19 @@ final class TestHook extends Hook {
}

@override
UnmodifiableMapView<String, LDValue> beforeIdentify(
UnmodifiableMapView<String, dynamic> beforeIdentify(
IdentifySeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data,
UnmodifiableMapView<String, dynamic> data,
) {
callLog.add('beforeIdentify');
identifyContexts.add(hookContext);
return data;
}

@override
UnmodifiableMapView<String, LDValue> afterIdentify(
UnmodifiableMapView<String, dynamic> afterIdentify(
IdentifySeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data,
UnmodifiableMapView<String, dynamic> data,
IdentifyResult result,
) {
callLog.add('afterIdentify');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export 'package:launchdarkly_common_client/launchdarkly_common_client.dart'
IdentifySeriesContext,
EvaluationSeriesContext,
TrackSeriesContext,
CredentialType;
CredentialType,
PluginSdkMetadata,
PluginCredentialInfo,
PluginEnvironmentMetadata,
PluginMetadata;

export 'src/ld_client.dart' show LDClient;
export 'src/config/ld_config.dart' show LDConfig, ApplicationEvents;
Expand Down
17 changes: 8 additions & 9 deletions packages/flutter_client_sdk/test/ld_client_plugin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'dart:async';
import 'dart:collection';

import 'package:flutter_test/flutter_test.dart';
import 'package:launchdarkly_common_client/launchdarkly_common_client.dart';
import 'package:launchdarkly_flutter_client_sdk/launchdarkly_flutter_client_sdk.dart';

import 'package:flutter/widgets.dart' as widgets;
Expand All @@ -27,34 +26,34 @@ final class TestHook extends Hook {
HookMetadata get metadata => _metadata;

@override
UnmodifiableMapView<String, LDValue> beforeEvaluation(
UnmodifiableMapView<String, dynamic> beforeEvaluation(
EvaluationSeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data) {
UnmodifiableMapView<String, dynamic> data) {
callLog.add('beforeEvaluation:$hookContext:$data');
return super.beforeEvaluation(hookContext, data);
}

@override
UnmodifiableMapView<String, LDValue> afterEvaluation(
UnmodifiableMapView<String, dynamic> afterEvaluation(
EvaluationSeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data,
UnmodifiableMapView<String, dynamic> data,
LDEvaluationDetail<LDValue> detail) {
callLog.add('afterEvaluation:$hookContext:$data:$detail');
return super.afterEvaluation(hookContext, data, detail);
}

@override
UnmodifiableMapView<String, LDValue> beforeIdentify(
UnmodifiableMapView<String, dynamic> beforeIdentify(
IdentifySeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data) {
UnmodifiableMapView<String, dynamic> data) {
callLog.add('beforeIdentify:$hookContext:$data');
return super.beforeIdentify(hookContext, data);
}

@override
UnmodifiableMapView<String, LDValue> afterIdentify(
UnmodifiableMapView<String, dynamic> afterIdentify(
IdentifySeriesContext hookContext,
UnmodifiableMapView<String, LDValue> data,
UnmodifiableMapView<String, dynamic> data,
IdentifyResult result) {
callLog.add('afterIdentify:$hookContext:$data:$result');
return super.afterIdentify(hookContext, data, result);
Expand Down