You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
733 B
25 lines
733 B
import 'package:redux/redux.dart';
|
|
import 'package:thesis_shop/redux/actions/actions.dart';
|
|
import 'package:thesis_shop/redux/state.dart';
|
|
import 'package:thesis_shop/service/product_service.dart';
|
|
|
|
class FetchProductsMiddleware {
|
|
final ProductService service;
|
|
|
|
const FetchProductsMiddleware(this.service);
|
|
|
|
void fetchTodosMiddleware(
|
|
Store<AppState> store, action, NextDispatcher next) {
|
|
if (action is FetchProductsAction) {
|
|
service
|
|
.fetchProducts()
|
|
.then(FetchProductsSucceededAction.new)
|
|
.then(store.dispatch)
|
|
.catchError((error) {
|
|
store.dispatch(
|
|
FetchProductsFailedAction(errorMessage: error.toString()));
|
|
});
|
|
}
|
|
next(action);
|
|
}
|
|
}
|
|
|