mirror of
https://github.com/hanskokx/arcane_framework.git
synced 2026-05-14 10:29:06 +02:00
Remove 'of' and 'requiredOf' locators
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -33,7 +33,7 @@ To use Arcane Framework in your Dart or Flutter project, follow these steps:
|
|||||||
runApp(
|
runApp(
|
||||||
ArcaneApp(
|
ArcaneApp(
|
||||||
services: [
|
services: [
|
||||||
MyArcaneService.I,
|
MyArcaneService(),
|
||||||
],
|
],
|
||||||
child: MainApp(),
|
child: MainApp(),
|
||||||
),
|
),
|
||||||
@@ -55,7 +55,7 @@ A service's purpose is to facilitate cross-feature communication of small pieces
|
|||||||
class FavoriteColorService extends ArcaneService {
|
class FavoriteColorService extends ArcaneService {
|
||||||
static final FavoriteColorService _instance = FavoriteColorService._internal();
|
static final FavoriteColorService _instance = FavoriteColorService._internal();
|
||||||
|
|
||||||
static FavoriteColorService get I => _instance;
|
factory FavoriteColorService() => I._instance;
|
||||||
|
|
||||||
FavoriteColorService._internal();
|
FavoriteColorService._internal();
|
||||||
|
|
||||||
|
|||||||
@@ -157,33 +157,4 @@ extension ServiceProviderExtension on BuildContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An abstract class representing a service in the Arcane architecture.
|
/// An abstract class representing a service in the Arcane architecture.
|
||||||
///
|
abstract class ArcaneService with ChangeNotifier {}
|
||||||
/// Classes that extend `ArcaneService` can use `ChangeNotifier` functionality
|
|
||||||
/// to notify listeners of changes. Services are typically registered in
|
|
||||||
/// `ArcaneServiceProvider` and can be accessed using the `service`
|
|
||||||
/// method on `BuildContext`.
|
|
||||||
abstract class ArcaneService with ChangeNotifier, ArcaneServiceLocators {}
|
|
||||||
|
|
||||||
mixin ArcaneServiceLocators<T> {
|
|
||||||
/// Retrieves a service of the specified type from the context.
|
|
||||||
///
|
|
||||||
/// Returns null if no service of type `T` is found.
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// ```dart
|
|
||||||
/// final myService = ArcaneService.of<MyService>(context);
|
|
||||||
/// ```
|
|
||||||
static T? of<T extends ArcaneService>(BuildContext context) =>
|
|
||||||
context.service<T>();
|
|
||||||
|
|
||||||
/// Retrieves a service of the specified type from the context.
|
|
||||||
///
|
|
||||||
/// Throws an assertion error if no service of type `T` is found.
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// ```dart
|
|
||||||
/// final myService = ArcaneService.requiredOf<MyService>(context);
|
|
||||||
/// ```
|
|
||||||
static T requiredOf<T extends ArcaneService>(BuildContext context) =>
|
|
||||||
context.requiredService<T>();
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user