diff --git a/README.md b/README.md index a8a2325..0ffce5c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ Opinionated modern event based application development framework. ### Upcoming -- Default navigator using Flutter Navigator 2.0 +- Default navigator using Flutter Navigator 2.0. +- Support adding custom TypedEventHandlers and EventBuses. ## Installation @@ -27,20 +28,69 @@ buzz: ref: main ``` -## Usage +## Initialization -### Initialization - -``dart +```dart Buzz..init( navigator: MyAppNavigator(), -), +); +``` + +## Fire Events + +By default the framework supports firing three base class events: +- `UiEvent` +- `Command` +- `AppEvent` + +Find pre-defined [out-of-the-box supported events](./docs/EVENTS.md). + +### UiEvents + +The library comes with a few pre-defined `UiEvents` you can find [here](./docs/EVENTS.md). + +For example, when a button/label is tapped: + +```dart +ElevatedButton( + onPressed: () { + Buzz.fire(OnTapped()); + }, + child: Text('Tap me!'), +) ``` -### Fire Events +### NavigationCommands -TODO: Add +The library comes with a few pre-defined `NavigationCommands` you can find [here](./docs/EVENTS.md). -### Listen Events +Go to a route: -TODO: Add +```dart +Buzz.fire( + NavigateToCommand.named('/my-route'), +); +``` + +or go back to previous route: + +```dart +Buzz.fire(NavigateBackCommand()); +``` + +## Listen Events + +Use the `on` method from the `TypedEventBus` component to get a `Stream` to listen events of a specific class type. + +For example, here is how we setup the listener for `NavigationCommands` as part of the features ready for you to use, this happens behind the insides: + +```dart +final commandBus = EventBusHolder.of(); +final navigationCommandStream = commandBus.on(); +navigationCommandStream.listen((navigationCommand) { + NavigationCommandHandler( + navigator: _navigator, + backDefault: _navigator.backDefaultRoute, + ).handle(navigationCommand); +}); +``` diff --git a/docs/EVENTS.md b/docs/EVENTS.md new file mode 100644 index 0000000..dc3b4e7 --- /dev/null +++ b/docs/EVENTS.md @@ -0,0 +1,24 @@ +# Events + +By default the framework supports firing three base class events: +- `UiEvent`: Defined as any User Interaction, it MUST be named behind user interface components. +- `Command`: Defined as requests to execute Business Logic. +- `AppEvent`: Defined as results from the execution of Business Logic code. + +## UiEvents + +Out-of-the-box supported UiEvents: +- `OnTapped`. +- `OnScroll` with `OnScrollDirection` enum. +- `OnSwipe` with `OnSwipeDirection` enum. +- `OnToggleChanged`. +- `OnFocusChanged`. +- `OnValueChanged`. +- `OnValueCopied`. +- `OnValuePasted`. + +## Commands + +### NavigationCommands + +## AppEvents