Skip to content

Commit

Permalink
[3.1.3] Increase dependencies versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Carapacik committed May 23, 2024
1 parent 7cc55a6 commit 809b193
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: "Run analyze"
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected].4
- uses: actions/[email protected].6
- uses: subosito/[email protected]
with:
channel: stable
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: "Deploy on Github Pages"
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected].4
- uses: actions/[email protected].6
- uses: subosito/[email protected]
with:
channel: stable
Expand Down
4 changes: 2 additions & 2 deletions lib/src/feature/app/logic/app_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ final class AppRunner {
Bloc.observer = const AppBlocObserver();
Bloc.transformer = bloc_concurrency.sequential();
const config = Config();
const initializationProcessor = InitializationProcessor(config);
const initializationProcessor = CompositionRoot(config);

Future<void> initializeAndRun() async {
try {
final result = await initializationProcessor.initialize();
final result = await initializationProcessor.compose();
// Attach this widget to the root of the tree.
runApp(App(result: result));
} on Object catch (e, stackTrace) {
Expand Down
5 changes: 2 additions & 3 deletions lib/src/feature/app/widget/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ class App extends StatelessWidget {
/// {@macro app}
const App({required this.result, super.key});

/// The initialization result from the [InitializationProcessor]
/// which contains initialized dependencies.
final InitializationResult result;
/// The result from the [CompositionRoot].
final CompositionResult result;

@override
Widget build(BuildContext context) => DependenciesScope(
Expand Down
57 changes: 30 additions & 27 deletions lib/src/feature/initialization/logic/initialization_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,41 @@ import 'package:wordly/src/feature/settings/data/theme_repository.dart';
import 'package:wordly/src/feature/statistic/data/statistics_datasource.dart';
import 'package:wordly/src/feature/statistic/data/statistics_repository.dart';

/// {@template initialization_processor}
/// A class which is responsible for processing initialization steps.
/// {@template composition_root}
/// A place where all dependencies are initialized.
/// {@endtemplate}
final class InitializationProcessor {
/// {@macro initialization_processor}
const InitializationProcessor(this.config);
///
/// {@template composition_process}
/// Composition of dependencies is a process of creating and configuring
/// instances of classes that are required for the application to work.
///
/// It is a good practice to keep all dependencies in one place to make it
/// easier to manage them and to ensure that they are initialized only once.
/// {@endtemplate}
final class CompositionRoot {
/// {@macro composition_root}
const CompositionRoot(this.config);

/// Application configuration
final Config config;

/// Composes dependencies and returns result of composition.
Future<CompositionResult> compose() async {
final stopwatch = Stopwatch()..start();

logger.info('Initializing dependencies...');
// initialize dependencies
final dependencies = await _initDependencies();
logger.info('Dependencies initialized');

stopwatch.stop();
final result = CompositionResult(
dependencies: dependencies,
msSpent: stopwatch.elapsedMilliseconds,
);
return result;
}

Future<Dependencies> _initDependencies() async {
final sharedPreferences = await SharedPreferences.getInstance();
final settingsBloc = await _initSettingsBloc(sharedPreferences);
Expand All @@ -45,7 +70,6 @@ final class InitializationProcessor {
StatisticsRepositoryImpl(statisticsDataSource: StatisticsDataSourceLocal(sharedPreferences: sharedPreferences));

return Dependencies(
sharedPreferences: sharedPreferences,
settingsBloc: settingsBloc,
gameRepository: gameRepository,
levelRepository: levelRepository,
Expand Down Expand Up @@ -84,25 +108,4 @@ final class InitializationProcessor {
);
return settingsBloc;
}

/// Initializes dependencies and returns the result of the initialization.
///
/// This method may contain additional steps that need initialization
/// before the application starts
/// (for example, caching or enabling tracking manager)
Future<InitializationResult> initialize() async {
final stopwatch = Stopwatch()..start();

logger.info('Initializing dependencies...');
// initialize dependencies
final dependencies = await _initDependencies();
logger.info('Dependencies initialized');

stopwatch.stop();
final result = InitializationResult(
dependencies: dependencies,
msSpent: stopwatch.elapsedMilliseconds,
);
return result;
}
}
27 changes: 14 additions & 13 deletions lib/src/feature/initialization/model/dependencies.dart
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:wordly/src/feature/game/data/game_repository.dart';
import 'package:wordly/src/feature/initialization/logic/initialization_processor.dart';
import 'package:wordly/src/feature/level/data/level_repository.dart';
import 'package:wordly/src/feature/settings/bloc/settings_bloc.dart';
import 'package:wordly/src/feature/statistic/data/statistics_repository.dart';

/// {@template dependencies}
/// Dependencies container
/// Composed dependencies from the [CompositionRoot].
///
/// This class is used to pass dependencies to the application.
///
/// {@macro composition_process}
/// {@endtemplate}
base class Dependencies {
/// {@macro dependencies}
const Dependencies({
required this.sharedPreferences,
required this.settingsBloc,
required this.gameRepository,
required this.levelRepository,
required this.statisticsRepository,
});

/// [SharedPreferences] instance, used to store Key-Value pairs.
final SharedPreferences sharedPreferences;

/// [SettingsBloc] instance, used to manage theme and locale.
final SettingsBloc settingsBloc;
final StatisticsRepository statisticsRepository;
final ILevelRepository levelRepository;
final IGameRepository gameRepository;
}

/// {@template initialization_result}
/// Result of initialization
/// {@template composition_result}
/// Result of composition
///
/// {@macro composition_process}
/// {@endtemplate}
final class InitializationResult {
/// {@macro initialization_result}
const InitializationResult({
final class CompositionResult {
/// {@macro composition_result}
const CompositionResult({
required this.dependencies,
required this.msSpent,
});
Expand All @@ -44,7 +45,7 @@ final class InitializationResult {
final int msSpent;

@override
String toString() => '$InitializationResult('
String toString() => '$CompositionResult('
'dependencies: $dependencies, '
'msSpent: $msSpent'
')';
Expand Down
Loading

0 comments on commit 809b193

Please sign in to comment.