55import functools
66import operator
77import uuid
8- from dataclasses import asdict , make_dataclass
8+ from dataclasses import asdict , fields , make_dataclass
99from typing import TYPE_CHECKING , Any , TypeVar , cast
1010
1111from .basic_types import (
1212 Action ,
1313 BaseAction ,
14+ BaseCombineReducerState ,
1415 BaseEvent ,
16+ CombineReducerAction ,
17+ CombineReducerInitAction ,
18+ CombineReducerRegisterAction ,
19+ CombineReducerUnregisterAction ,
1520 CompleteReducerResult ,
1621 Event ,
17- Immutable ,
1822 InitAction ,
1923 is_complete_reducer_result ,
2024)
2327 from redux import ReducerType
2428
2529
26- class BaseCombineReducerState (Immutable ):
27- _id : str
28-
29-
30- class CombineReducerAction (BaseAction ):
31- _id : str
32-
33-
34- class CombineReducerInitAction (CombineReducerAction , InitAction ):
35- key : str
36-
37-
38- class CombineReducerRegisterAction (CombineReducerAction ):
39- key : str
40- reducer : ReducerType
41-
42-
43- class CombineReducerUnregisterAction (CombineReducerAction ):
44- key : str
45-
46-
4730CombineReducerState = TypeVar (
4831 'CombineReducerState' ,
4932 bound = BaseCombineReducerState ,
@@ -64,7 +47,7 @@ def combine_reducers(
6447 state_class = cast (
6548 type [state_type ],
6649 make_dataclass (
67- 'combined_reducer' ,
50+ state_type . __name__ ,
6851 ('_id' , * reducers .keys ()),
6952 frozen = True ,
7053 kw_only = True ,
@@ -84,9 +67,10 @@ def combined_reducer(
8467 reducer = action .reducer
8568 reducers [key ] = reducer
8669 state_class = make_dataclass (
87- 'combined_reducer' ,
70+ state_type . __name__ ,
8871 ('_id' , * reducers .keys ()),
8972 frozen = True ,
73+ kw_only = True ,
9074 )
9175 reducer_result = reducer (
9276 None ,
@@ -123,11 +107,16 @@ def combined_reducer(
123107 key = action .key
124108
125109 del reducers [key ]
126- fields_copy = copy . copy ( cast ( Any , state_class ). __dataclass_fields__ )
110+ fields_copy = { field . name : field for field in fields ( state_class )}
127111 annotations_copy = copy .deepcopy (state_class .__annotations__ )
128112 del fields_copy [key ]
129113 del annotations_copy [key ]
130- state_class = make_dataclass ('combined_reducer' , annotations_copy )
114+ state_class = make_dataclass (
115+ state_type .__name__ ,
116+ annotations_copy ,
117+ frozen = True ,
118+ kw_only = True ,
119+ )
131120 cast (Any , state_class ).__dataclass_fields__ = fields_copy
132121
133122 state = state_class (
0 commit comments