11part of 'hooks.dart' ;
22
33/// A store of mutable state that allows mutations by dispatching actions.
4- abstract class Store <State , Action > {
4+ abstract class Store <StateT , ActionT > {
55 /// The current state.
66 ///
77 /// This value may change after a call to [dispatch] .
8- State get state;
8+ StateT get state;
99
1010 /// Dispatches an action.
1111 ///
1212 /// Actions are dispatched synchronously.
1313 /// It is impossible to try to dispatch actions during `build` .
14- void dispatch (Action action);
14+ void dispatch (ActionT action);
1515}
1616
1717/// Composes an [Action] and a [State] to create a new [State] .
@@ -33,10 +33,10 @@ typedef Reducer<State, Action> = State Function(State state, Action action);
3333/// See also:
3434/// * [Reducer]
3535/// * [Store]
36- Store <State , Action > useReducer <State , Action >(
37- Reducer <State , Action > reducer, {
38- required State initialState,
39- required Action initialAction,
36+ Store <StateT , ActionT > useReducer <StateT , ActionT >(
37+ Reducer <StateT , ActionT > reducer, {
38+ required StateT initialState,
39+ required ActionT initialAction,
4040}) {
4141 return use (
4242 _ReducerHook (
@@ -47,27 +47,27 @@ Store<State, Action> useReducer<State, Action>(
4747 );
4848}
4949
50- class _ReducerHook <State , Action > extends Hook <Store <State , Action >> {
50+ class _ReducerHook <StateT , ActionT > extends Hook <Store <StateT , ActionT >> {
5151 const _ReducerHook (
5252 this .reducer, {
5353 required this .initialState,
5454 required this .initialAction,
5555 });
5656
57- final Reducer <State , Action > reducer;
58- final State initialState;
59- final Action initialAction;
57+ final Reducer <StateT , ActionT > reducer;
58+ final StateT initialState;
59+ final ActionT initialAction;
6060
6161 @override
62- _ReducerHookState <State , Action > createState () =>
63- _ReducerHookState <State , Action >();
62+ _ReducerHookState <StateT , ActionT > createState () =>
63+ _ReducerHookState <StateT , ActionT >();
6464}
6565
66- class _ReducerHookState <State , Action >
67- extends HookState <Store <State , Action >, _ReducerHook <State , Action >>
68- implements Store <State , Action > {
66+ class _ReducerHookState <StateT , ActionT >
67+ extends HookState <Store <StateT , ActionT >, _ReducerHook <StateT , ActionT >>
68+ implements Store <StateT , ActionT > {
6969 @override
70- late State state = hook.reducer (hook.initialState, hook.initialAction);
70+ late StateT state = hook.reducer (hook.initialState, hook.initialAction);
7171
7272 @override
7373 void initHook () {
@@ -77,7 +77,7 @@ class _ReducerHookState<State, Action>
7777 }
7878
7979 @override
80- void dispatch (Action action) {
80+ void dispatch (ActionT action) {
8181 final newState = hook.reducer (state, action);
8282
8383 if (state != newState) {
@@ -86,7 +86,7 @@ class _ReducerHookState<State, Action>
8686 }
8787
8888 @override
89- Store <State , Action > build (BuildContext context) {
89+ Store <StateT , ActionT > build (BuildContext context) {
9090 return this ;
9191 }
9292
0 commit comments