1
0
Fork 0
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.
 
 
 
 
 
thesis_shop/lib/redux/middlewares/fetch_products_middleware.dart

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);
}
}