redux.dart icon indicating copy to clipboard operation
redux.dart copied to clipboard

add TypedMiddlewareBase abstraction

Open dzziwny opened this issue 2 years ago • 0 comments

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.

dzziwny avatar Apr 23 '22 17:04 dzziwny