Skip to content

Commit

Permalink
refactor: update registries naming and remove class
Browse files Browse the repository at this point in the history
  • Loading branch information
luisburgos committed Aug 6, 2022
1 parent 44842ae commit 0b00b15
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 37 deletions.
2 changes: 1 addition & 1 deletion example/lib/get/core_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CoreModule extends GetModule {
..init(
navigator: GetAppNavigator(),
feedbacksExecutor: GetFeedbacksExecutor(),
moduleRegistries: [
eventHandlersRegistries: [
ProfileModuleRegistries(
() => Get.find<IProfileRepository>(),
),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/modular/core_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CoreModule extends Module {
(i) => Buzz
..init(
navigator: ModularAppNavigator(),
moduleRegistries: [
eventHandlersRegistries: [
ProfileModuleRegistries(
() => Modular.get<IProfileRepository>(),
),
Expand Down
16 changes: 8 additions & 8 deletions lib/buzz_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class IBuzzBase {
void init({
required Navigator navigator,
FeedbacksExecutor? feedbacksExecutor,
List<BuzzEventHandlersRegistries>? moduleRegistries,
List<BuzzEventHandlersRegistries>? eventHandlersRegistries,
});

void fire(dynamic message);
Expand All @@ -50,17 +50,17 @@ class BuzzBase implements IBuzzBase {

late Navigator _navigator;
late FeedbacksExecutor _feedbacksExecutor;
List<BuzzEventHandlersRegistries>? _moduleRegistries;
List<BuzzEventHandlersRegistries>? _eventHandlersRegistries;

@override
void init({
required Navigator navigator,
FeedbacksExecutor? feedbacksExecutor,
List<BuzzEventHandlersRegistries>? moduleRegistries,
List<BuzzEventHandlersRegistries>? eventHandlersRegistries,
}) {
_navigator = navigator;
_feedbacksExecutor = feedbacksExecutor ?? DefaultFeedbacksExecutor();
_moduleRegistries = moduleRegistries;
_eventHandlersRegistries = eventHandlersRegistries;

_bindNavigationCommandHandler();
_bindRegistries();
Expand Down Expand Up @@ -94,10 +94,10 @@ class BuzzBase implements IBuzzBase {
}

void _bindRegistries() {
_moduleRegistries?.forEach((moduleRegistry) {
uiEvents.bindRegistries(moduleRegistry.uiEvents);
commands.bindRegistries(moduleRegistry.commands);
appEvents.bindRegistries(moduleRegistry.appEvents);
_eventHandlersRegistries?.forEach((eventHandlerRegistry) {
uiEvents.bindRegistries(eventHandlerRegistry.uiEvents);
commands.bindRegistries(eventHandlerRegistry.commands);
appEvents.bindRegistries(eventHandlerRegistry.appEvents);
});
}
}
18 changes: 0 additions & 18 deletions lib/infra/registries.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
import 'package:buzz/buzz.dart';

abstract class IBuzzDataRegistries {
List<DataRegistry> get registries;
}

abstract class BuzzDataRegistries extends IBuzzDataRegistries {}

class DataRegistry<T> {
DataRegistry({
required this.binder,
});

final Function(T) binder;
dynamic get registryType => T;

@override
String toString() => '$runtimeType type: $T handler: $binder';
}

abstract class IBuzzEventHandlersRegistries {
List<CommandRegistry> get commands;
List<UiEventRegistry> get uiEvents;
Expand Down
9 changes: 0 additions & 9 deletions test/registries_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,4 @@ void main() {
);
expect(registry.registryType, BaseAppEvent);
});

test('DataRegistry.registryType works for fake repository', () {
final registry = DataRegistry<FakeDataRepository>(
binder: (repository) {
print('Add $repository to DI');
},
);
expect(registry.registryType, FakeDataRepository);
});
}

0 comments on commit 0b00b15

Please sign in to comment.