Skip to content

Commit a8573a7

Browse files
committed
refactor: rename _id field of combine reducer state to combine_reducers_id
1 parent b789424 commit a8573a7

32 files changed

+175
-167
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- refactor: move the common code for manipulating the signature of the wrapped functions in `WithStore` and `Autorun` to a utility function
77
- feat: support `with_state` to be applied to methods of classes, not just functions
88
- feat: support `view` to be applied to methods of classes, not just functions, it works for `autorun` too, but only when it is being called directly like a view
9+
- refactor: rename `_id` field of combine reducer state to `combine_reducers_id`
910

1011
## Version 0.23.0
1112

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ You can then add a new reducer to it using the `reducer_id` like this:
275275
```python
276276
store.dispatch(
277277
CombineReducerRegisterAction(
278-
_id=reducer_id,
278+
combine_reducers_id=reducer_id,
279279
key='third',
280280
third=third_reducer,
281281
),
@@ -287,7 +287,7 @@ You can also remove a reducer from it like this:
287287
```python
288288
store.dispatch(
289289
CombineReducerRegisterAction(
290-
_id=reducer_id,
290+
combine_reducers_id=reducer_id,
291291
key='second',
292292
),
293293
)

demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def render(base10_value: CountStateType) -> int:
156156

157157
store.dispatch(
158158
CombineReducerRegisterAction(
159-
_id=reducer_id,
159+
combine_reducers_id=reducer_id,
160160
key='inverse',
161161
reducer=inverse_reducer,
162162
),
@@ -167,7 +167,7 @@ def render(base10_value: CountStateType) -> int:
167167

168168
store.dispatch(
169169
CombineReducerUnregisterAction(
170-
_id=reducer_id,
170+
combine_reducers_id=reducer_id,
171171
key='straight',
172172
),
173173
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ classifiers = [
1919
[tool.uv]
2020
dev-dependencies = [
2121
"poethepoet >= 0.24.4",
22-
"pyright >= 1.1.400",
22+
"pyright >= 1.1.401",
2323
"ruff >= 0.11.8",
2424
"pytest >= 8.1.1",
2525
"pytest-cov >= 4.1.0",

redux/basic_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,11 @@ def __call__(
471471

472472

473473
class BaseCombineReducerState(Immutable):
474-
_id: str
474+
combine_reducers_id: str
475475

476476

477477
class CombineReducerAction(BaseAction):
478-
_id: str
478+
combine_reducers_id: str
479479

480480

481481
class CombineReducerInitAction(CombineReducerAction, InitAction, Generic[Payload]):

redux/combine_reducers.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ def combine_reducers(
4444
) -> tuple[ReducerType[CombineReducerState, Action, Event], str]:
4545
_ = action_type, event_type
4646
reducers = reducers.copy()
47-
_id = uuid.uuid4().hex
47+
id_ = uuid.uuid4().hex
4848

49-
state_class = make_immutable(state_type.__name__, (('_id', str), *reducers.keys()))
49+
state_class = make_immutable(
50+
state_type.__name__,
51+
(('combine_reducers_id', str), *reducers.keys()),
52+
)
5053

5154
def combined_reducer(
5255
state: CombineReducerState | None,
@@ -58,22 +61,26 @@ def combined_reducer(
5861
if (
5962
state is not None
6063
and isinstance(action, CombineReducerAction)
61-
and action._id == _id # noqa: SLF001
64+
and action.combine_reducers_id == id_
6265
):
6366
if isinstance(action, CombineReducerRegisterAction):
6467
key = action.key
6568
reducer = action.reducer
6669
reducers[key] = reducer
6770
state_class = make_immutable(
6871
state_type.__name__,
69-
(('_id', str), *reducers.keys()),
72+
(('combine_reducers_id', str), *reducers.keys()),
7073
)
7174
reducer_result = reducer(
7275
None,
73-
CombineReducerInitAction(_id=_id, key=key, payload=action.payload),
76+
CombineReducerInitAction(
77+
combine_reducers_id=id_,
78+
key=key,
79+
payload=action.payload,
80+
),
7481
)
7582
state = state_class(
76-
_id=state._id, # noqa: SLF001
83+
combine_reducers_id=state.combine_reducers_id,
7784
**{
7885
key_: (
7986
reducer_result.state
@@ -107,21 +114,21 @@ def combined_reducer(
107114
state_class.__dataclass_fields__ = fields_copy
108115

109116
state = state_class(
110-
_id=state._id, # noqa: SLF001
117+
combine_reducers_id=state.combine_reducers_id,
111118
**{key_: getattr(state, key_) for key_ in reducers if key_ != key},
112119
)
113120

114121
reducers_results = {
115122
key: reducer(
116123
None if state is None else getattr(state, key),
117-
CombineReducerInitAction(key=key, _id=_id)
124+
CombineReducerInitAction(key=key, combine_reducers_id=id_)
118125
if isinstance(action, InitAction)
119126
else action,
120127
)
121128
for key, reducer in reducers.items()
122129
}
123130
result_state = state_class(
124-
_id=_id,
131+
combine_reducers_id=id_,
125132
**{
126133
key: result.state if is_complete_reducer_result(result) else result
127134
for key, result in reducers_results.items()
@@ -150,4 +157,4 @@ def combined_reducer(
150157
events=result_events,
151158
)
152159

153-
return combined_reducer, _id
160+
return combined_reducer, id_

tests/results/test_features/general/store-000.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-000
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 10
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"straight": {
1010
"_type": "CountStateType",
1111
"count": 0

tests/results/test_features/general/store-001.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-001
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 11
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"straight": {
1010
"_type": "CountStateType",
1111
"count": 1

tests/results/test_features/general/store-002.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-002
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 12
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"inverse": {
1010
"_type": "CountStateType",
1111
"count": -1

tests/results/test_features/general/store-003.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-003
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 12
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"inverse": {
1010
"_type": "CountStateType",
1111
"count": -1

tests/results/test_features/general/store-004.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-004
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 10
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"inverse": {
1010
"_type": "CountStateType",
1111
"count": 1

tests/results/test_features/general/store-005.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-005
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 8
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"inverse": {
1010
"_type": "CountStateType",
1111
"count": 3

tests/results/test_features/general/store-autorun-000.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-autorun-000
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 10
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"straight": {
1010
"_type": "CountStateType",
1111
"count": 0

tests/results/test_features/general/store-autorun-001.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-autorun-001
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 11
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"straight": {
1010
"_type": "CountStateType",
1111
"count": 1

tests/results/test_features/general/store-autorun-002.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-autorun-002
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 12
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"inverse": {
1010
"_type": "CountStateType",
1111
"count": -1

tests/results/test_features/general/store-autorun-003.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-autorun-003
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 10
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"inverse": {
1010
"_type": "CountStateType",
1111
"count": 1

tests/results/test_features/general/store-autorun-004.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-autorun-004
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 8
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"inverse": {
1010
"_type": "CountStateType",
1111
"count": 3

tests/results/test_features/general/store-autorun_subscription-000.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-autorun_subscription-000
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 10
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"straight": {
1010
"_type": "CountStateType",
1111
"count": 0

tests/results/test_features/general/store-autorun_subscription-001.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-autorun_subscription-001
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 11
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"straight": {
1010
"_type": "CountStateType",
1111
"count": 1

tests/results/test_features/general/store-autorun_subscription-002.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-autorun_subscription-002
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 12
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"inverse": {
1010
"_type": "CountStateType",
1111
"count": -1

tests/results/test_features/general/store-autorun_subscription-003.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-autorun_subscription-003
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 10
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"inverse": {
1010
"_type": "CountStateType",
1111
"count": 1

tests/results/test_features/general/store-autorun_subscription-004.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-autorun_subscription-004
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 8
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"inverse": {
1010
"_type": "CountStateType",
1111
"count": 3

tests/results/test_features/general/store-subscription-000.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-subscription-000
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 11
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"straight": {
1010
"_type": "CountStateType",
1111
"count": 1

tests/results/test_features/general/store-subscription-001.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-subscription-001
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 11
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"inverse": {
1010
"_type": "CountStateType",
1111
"count": 0

tests/results/test_features/general/store-subscription-002.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// store-subscription-002
22
{
3-
"_id": "e3e70682c2094cac629f6fbed82c07cd",
43
"_type": "StateType",
54
"base10": {
65
"_type": "CountStateType",
76
"count": 11
87
},
8+
"combine_reducers_id": "e3e70682c2094cac629f6fbed82c07cd",
99
"inverse": {
1010
"_type": "CountStateType",
1111
"count": 0

0 commit comments

Comments
 (0)