fluttercommunity / redux.dart

Redux for Dart
https://pub.dev/packages/redux
MIT License
515 stars 61 forks source link

Middleware creation failure does not throw error #58

Open elvisun opened 4 years ago

elvisun commented 4 years ago

For the following code:

List<Middleware<AppState>> createMiddlewares() {
  final onFetchWishListMiddleware = _onFetchWishList();

  return [
    TypedMiddleware<AppState, FetchWishListAction>(onFetchWishListMiddleware),
  ];
}

Middleware<AppState> _onFetchSomething(SomethingService service) {
  return (Store<AppState> store, action, NextDispatcher next) async* {
    next(action);

    var user = selectors.getCurrentUser(store.state);

    service.list().listen((List<Something> items) {
      store.dispatch(FetchSomethingSuccessAction(items));
    });
  };
}

I accidentally put in async* which shouldn't be there, then this action's middleware and reducer wouldn't run, but it also didn't throw any error. Are we able to provide Middleware with a better type so we get warnings on things like this early?

Filed an issue in flutter_redux but we thought it's better suited here (https://github.com/brianegan/flutter_redux/issues/178)