rx_reactor

Last updated:

0 purchases

rx_reactor Image
rx_reactor Images
Add to Cart

Description:

rx reactor

Features #
Simple MVVM reactive programming tool using ReactiveX for flutter.
It helps to completely separate business logic from view.
The fundamental idea comes from ReactorKit [https://github.com/ReactorKit/ReactorKit].
Getting started #
Add the dependency in pubspec.yaml:
dependencies:
...
rx_reactor_flutter: ^0.3.0
copied to clipboard
Usage #
Reactor

/// declare actions
enum _Action {
setTabItem,
}

/// declare mutations
enum _Mutation {
setTabItem,
}

/// state
class MainScreenState {
final selectedTabIndex = BehaviorSubject.seeded(0);
}

/// inherits from ContextReactor
class MainScreenReactor extends ContextReactor<MainState> {
@override
final state = MainState();

setTabItem(int index) =>
action.add(ReactAction(id: _Action.setTabItem, data: index));

@override
Stream<ReactMutation> mutate(ReactAction action) {
switch (action.id as _Action) {
case _Action.setTabItem:
return Stream<ReactMutation>.value(
ReactMutation(id: _Mutation.setTabItem, data: action.data));
}
}

@override
void reduce(ReactMutation mutation, MainState state) async {
switch (mutation.id as _Mutation) {
case _Mutation.setTabItem:
state.selectedTabIndex.add(mutation.data);
break;
}
}
}
copied to clipboard
View
class MainScreen extends StatelessWidget {
final reactor = MainScreenReactor();
@override
Widget build(BuildContext context) {
return ReactBuilder(
reactor: reactor,
builder: (context, reactor) {
...
}
);
}
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.