fluttercommunity / redux.dart

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

add TypedMiddlewareBase abstraction #82

Open dzziwny opened 2 years ago

dzziwny commented 2 years ago

Added typed middleware base abstraction, that allows to create a typed middleware as a simple class, like ex.

class MyMiddleware extends TypedMiddlewareBase<State, MyAction> {
  @override
  dynamic dispatch(Store<String> store, MyAction action, NextDispatcher next) {
    ...
  }
}

final store = new Store<State>(
  middleware: [MyMiddleware()],
);

Or TypedMiddlewareClass would be better, as there is already MiddlewareClass abstraction. Please leave a comment, do you see it useful. It's good if you prefer to keep project fully in OOP convention.

Otherwise, if you want to extend TypedMiddleware, you need to create something ugly like

class MyMiddleware<State, Action> extends TypedMiddleware<State, Action> {
  MyMiddleware()
      : super(
          (Store<State> store, Action action, NextDispatcher next) {
            ...
          },
        );
}

And within constructor it is no able to use other class properties.