https://github.com/hoc081098/flutter_github_search_rx_redux
🔰 Flutter github search using rx_redux | Functional & reactive programming with rxdart, rx_redux
https://github.com/hoc081098/flutter_github_search_rx_redux
flutter-bloc flutter-bloc-pattern flutter-bloc-pattern-rxdart flutter-bloc-rxdart flutter-redux flutter-redux-demo flutter-redux-epics rx-redux rxdart rxdart-bloc rxdart-epic rxdart-flutter rxdart-redux rxredux
Last synced: 27 days ago
JSON representation
🔰 Flutter github search using rx_redux | Functional & reactive programming with rxdart, rx_redux
- Host: GitHub
- URL: https://github.com/hoc081098/flutter_github_search_rx_redux
- Owner: hoc081098
- License: apache-2.0
- Created: 2020-09-01T12:00:49.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T17:44:37.000Z (over 1 year ago)
- Last Synced: 2025-02-12T13:54:31.565Z (3 months ago)
- Topics: flutter-bloc, flutter-bloc-pattern, flutter-bloc-pattern-rxdart, flutter-bloc-rxdart, flutter-redux, flutter-redux-demo, flutter-redux-epics, rx-redux, rxdart, rxdart-bloc, rxdart-epic, rxdart-flutter, rxdart-redux, rxredux
- Language: Dart
- Homepage: https://pub.dev/packages/rx_redux
- Size: 47.9 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# flutter_github_search_rx_redux
- Flutter github search using [rx_redux](https://pub.dev/packages/rx_redux)
- Functional & reactive programming with [rxdart](https://pub.dev/packages/rxdart), [rx_redux](https://pub.dev/packages/rx_redux) 🚀[](https://github.com/hoc081098/flutter_github_search_rx_redux/actions/workflows/flutter.yml)
![]()
## Demo
### Android
![]()
### MacOS desktop
![]()
## Effects with RxDart
```dart
import 'package:flutter_github_search_rx_redux/domain/search_usecase.dart';
import 'package:rx_redux/rx_redux.dart';
import 'package:rxdart_ext/rxdart_ext.dart';import 'home_action.dart';
import 'home_state.dart';RxReduxStore createStore(SearchUseCase searchUseCase) =>
RxReduxStore(
initialState: HomeState.initial(),
sideEffects: HomeSideEffects(searchUseCase)(),
reducer: (state, action) => action.reduce(state),
logger: rxReduxDefaultLogger,
);class HomeSideEffects {
final SearchUseCase _searchUseCase;HomeSideEffects(this._searchUseCase);
List> call() => [
searchActionToTextChangedAction,
search,
nextPage,
retry,
];Stream searchActionToTextChangedAction(
Stream actions,
GetState getState,
) =>
actions
.whereType()
.debounceTime(const Duration(milliseconds: 500))
.map((action) => action.term.trim())
.where((term) => term.isNotEmpty)
.distinct()
.map((term) => TextChangedAction((b) => b..term = term));Stream search(
Stream actions,
GetState getState,
) =>
actions
.whereType()
.map((action) => action.term)
.switchMap((term) => _nextPage(term, 1));Stream nextPage(
Stream actions,
GetState getState,
) {
final textChangedAction$ = actions.whereType().debug();final performLoadingNextPage = (LoadNextPageAction action) {
return Stream.value(getState())
.where((state) => state.canLoadNextPage)
.exhaustMap((state) => _nextPage(state.term, state.page + 1)
.takeUntil(textChangedAction$)
.debug());
};return actions
.whereType()
.exhaustMap(performLoadingNextPage);
}Stream retry(
Stream actions,
GetState getState,
) {
final textChangedAction$ = actions.whereType().debug();final performRetry = (RetryAction action) {
return Stream.value(getState())
.where((state) => state.canRetry)
.exhaustMap((state) => _nextPage(state.term, state.page + 1)
.takeUntil(textChangedAction$)
.debug());
};return actions.whereType().exhaustMap(performRetry);
}Stream _nextPage(String term, int nextPage) {
final loadingAction = SearchLoadingAction((b) => b
..term = term
..nextPage = nextPage);return Rx.fromCallable(() => _searchUseCase(term: term, page: nextPage))
.map(
(items) => SearchSuccessAction((b) => b
..term = term
..items.replace(items)),
)
.startWith(loadingAction)
.onErrorReturnWith(
(e, s) => SearchFailureAction((b) => b
..error = e
..term = term),
);
}
}
```