An open API service indexing awesome lists of open source software.

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

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) 🚀

[![Flutter](https://github.com/hoc081098/flutter_github_search_rx_redux/actions/workflows/flutter.yml/badge.svg)](https://github.com/hoc081098/flutter_github_search_rx_redux/actions/workflows/flutter.yml)


Logo

## 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),
);
}
}
```