Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add doc comments - Add `Experiment.defaultVariant` - `Experiment.active` only returns true when user is part of experiment. - Add `inactiveStringValue` to `ExperimentConfig` constructor - Make `LocalExperimentAdapter` parameter named (`resolveUserSeed`) - Make `FirebaseExperimentAdapter` parameters named - Add `FirebaseExperimentAdapter.remoteConfig`
- Loading branch information
Showing
18 changed files
with
289 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ build/ | |
/firebase/pubspec.lock | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
pubspec_overrides.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dart.lineLength": 120 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
library core; | ||
|
||
export 'src/adapter.dart'; | ||
export 'src/config.dart'; | ||
export 'src/experiment.dart'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,63 @@ | ||
import 'package:ab_testing_core/src/adapter.dart'; | ||
import 'package:ab_testing_core/src/experiment.dart'; | ||
|
||
/// A logger that is used to log experiment information. | ||
abstract class ExperimentLogger { | ||
void log(String message); | ||
void logExperiments(List<Experiment> experiments); | ||
} | ||
|
||
/// Base class for an application's experiment configuration. | ||
class ExperimentConfig { | ||
final List<ExperimentAdapter> _adapters; | ||
final ExperimentLogger? _logger; | ||
final String? _inactiveStringValue; | ||
|
||
ExperimentConfig(this._adapters, [this._logger]); | ||
ExperimentConfig( | ||
this._adapters, { | ||
ExperimentLogger? logger, | ||
String? inactiveStringValue, | ||
}) : _logger = logger, | ||
_inactiveStringValue = inactiveStringValue; | ||
|
||
List<Experiment> get _allExperiments => _adapters.expand((adapter) => adapter.experiments).toList(); | ||
/// All active experiments. | ||
List<Experiment> get experiments => _allExperiments.where((value) => value.active).toList(); | ||
|
||
List<Experiment> get _allExperiments => _adapters.expand((adapter) => adapter.experiments).toList(); | ||
|
||
/// Initializes all adapters. | ||
Future<void> init() async { | ||
await Future.wait(_adapters.map((adapter) => adapter.init())); | ||
update(); | ||
_logger?.logExperiments(experiments); | ||
} | ||
|
||
/// Updates all updatable adapters. | ||
Future<void> update({bool force = false}) async { | ||
final adapters = _adapters.whereType<UpdatableExperimentAdapter>(); | ||
if (adapters.isNotEmpty) { | ||
await Future.wait(adapters.map((adapter) => adapter.update(force: force))); | ||
if (force){ | ||
if (force) { | ||
_logger?.logExperiments(experiments); | ||
} | ||
} | ||
} | ||
|
||
Map<String, String> asMap() => {for (var item in _allExperiments) item.id: item.stringValue}; | ||
/// Returns a mapping of all experiments from their id to their string | ||
/// value. | ||
/// | ||
/// If [inactiveStringValue] is set, all inactive experiments will be mapped | ||
/// to this value. | ||
Map<String, String> asMap() => { | ||
for (final experiment in _allExperiments) // | ||
experiment.id: _experimentMapValue(experiment) | ||
}; | ||
|
||
String _experimentMapValue(Experiment experiment) { | ||
final inactiveStringValue = _inactiveStringValue; | ||
if (inactiveStringValue == null) { | ||
return experiment.stringValue; | ||
} | ||
return experiment.active ? experiment.stringValue : inactiveStringValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.