1+ import 'package:built_value/built_value.dart' ;
2+
13import 'action.dart' ;
24import 'built_reducer.dart' ;
35import 'store.dart' ;
46import 'typedefs.dart' ;
57
68/// [MiddlewareApi] put in scope to your [Middleware] function by redux.
79/// When using [MiddlwareBuilder] (recommended) [MiddlewareApi] is passed to your [MiddlewareHandler]
8- class MiddlewareApi <State extends BuiltReducer , Actions extends ReduxActions > {
9- Store <State , Actions > _store;
10+ class MiddlewareApi <State extends BuiltReducer <State , StateBuilder >,
11+ StateBuilder extends Builder <State , StateBuilder >, Actions extends ReduxActions > {
12+ Store <State , StateBuilder , Actions > _store;
1013 MiddlewareApi (this ._store);
1114
1215 /// [state] returns the current state
@@ -18,28 +21,32 @@ class MiddlewareApi<State extends BuiltReducer, Actions extends ReduxActions> {
1821
1922/// [MiddlwareBuilder] allows you to build a reducer that handles many different actions
2023/// with many different payload types, while maintaining type safety.
21- /// Each [MiddlewareHandler] added with add<T> must take a state of type V , an Action of type
24+ /// Each [MiddlewareHandler] added with add<T> must take a state of type State , an Action of type
2225/// Action<T>, and a builder of type B
23- class MiddlwareBuilder <State extends BuiltReducer , Actions extends ReduxActions > {
24- var _map = new Map <String , MiddlewareHandler <State , Actions >>();
26+ class MiddlwareBuilder <State extends BuiltReducer <State , StateBuilder >,
27+ StateBuilder extends Builder <State , StateBuilder >, Actions extends ReduxActions > {
28+ var _map = new Map <String , MiddlewareHandler <State , StateBuilder , Actions >>();
2529
26- add <T >(ActionName <T > aMgr, MiddlewareHandler <State , Actions > handler) => _map[aMgr.name] =
27- handler;
30+ add <T >(ActionName <T > aMgr, MiddlewareHandler <State , StateBuilder , Actions > handler) =>
31+ _map[aMgr.name] = handler;
2832
2933 /// build returns a [Middlware] function that handles all actions added with [add]
30- build () => (MiddlewareApi <State , Actions > api) => (ActionHandler next) => (Action action) {
31- var handler = _map[action.name];
32- if (handler != null ) {
33- handler (api, next, action);
34- return ;
35- }
36-
37- next (action);
38- };
34+ build () =>
35+ (MiddlewareApi <State , StateBuilder , Actions > api) => (ActionHandler next) => (Action action) {
36+ var handler = _map[action.name];
37+ if (handler != null ) {
38+ handler (api, next, action);
39+ return ;
40+ }
41+
42+ next (action);
43+ };
3944}
4045
4146/// [MiddlewareHandler] is a function that handles an action in a middleware. Its is only for
4247/// use with [MiddlwareBuilder] . If you are not using [MiddlwareBuilder] middleware must be
4348/// decalred as a [Middleware] function.
44- typedef MiddlewareHandler <State extends BuiltReducer , Actions extends ReduxActions >(
45- MiddlewareApi <State , Actions > api, ActionHandler next, Action action);
49+ typedef MiddlewareHandler <
50+ State extends BuiltReducer <State , StateBuilder >,
51+ StateBuilder extends Builder <State , StateBuilder >,
52+ Actions extends ReduxActions >(MiddlewareApi <State , StateBuilder , Actions > api, ActionHandler next, Action action);
0 commit comments