Skip to content

Commit 7033c8f

Browse files
committed
refactor(combine_reducers): add custom payload to CombineReducerInitAction and CombineReducerRegisterAction to allow custom initialization of sub-reducers
1 parent 7416592 commit 7033c8f

File tree

9 files changed

+112
-106
lines changed

9 files changed

+112
-106
lines changed

.github/workflows/integration_delivery.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ jobs:
4646
- uses: actions/checkout@v4
4747
name: Checkout
4848

49+
- name: Setup Python
50+
uses: actions/setup-python@v5
51+
with:
52+
python-version: ${{ env.PYTHON_VERSION }}
53+
4954
- name: Install uv
5055
uses: astral-sh/setup-uv@v3
5156
with:
@@ -68,11 +73,6 @@ jobs:
6873
- uses: actions/checkout@v4
6974
name: Checkout
7075

71-
- name: Setup Python
72-
uses: actions/setup-python@v5
73-
with:
74-
python-version: ${{ env.PYTHON_VERSION }}
75-
7676
- name: Install uv
7777
uses: astral-sh/setup-uv@v3
7878
with:

.gitignore

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,11 @@ env/
8787
venv/
8888
ENV/
8989

90-
# Spyder project settings
91-
.spyderproject
92-
.spyproject
93-
94-
# Rope project settings
95-
.ropeproject
90+
# hatch
91+
redux/_version.py
9692

9793
# mkdocs documentation
9894
/site
9995

10096
# mypy
10197
.mypy_cache/
102-
103-
# hatch
104-
redux/_version.py

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Version 0.18.3
4+
5+
- refactor(combine_reducers): add custom payload to `CombineReducerInitAction` and `CombineReducerRegisterAction` to allow custom initialization of sub-reducers
6+
37
## Version 0.18.2
48

59
- chore(pytest): add `project.entry-points.pytest11` section to `pyproject.toml` so that it can be used as a pytest plugin

pyproject.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name = "python-redux"
33
dynamic = ["version"]
44
description = "Redux implementation for Python"
55
license = { text = "Apache-2.0" }
6+
authors = [{ name = "Sassan Haradji", email = "me@sassanh.com" }]
7+
maintainers = [{ name = "Sassan Haradji", email = "me@sassanh.com" }]
68
readme = "README.md"
79
requires-python = ">=3.11"
810
keywords = ['store', 'redux', 'reactive', 'autorun']
@@ -20,6 +22,12 @@ dev-dependencies = [
2022
"tenacity >= 8.2.3",
2123
]
2224

25+
[project.urls]
26+
homepage = 'https://github.com/sassanh/python-redux/'
27+
repository = 'https://github.com/sassanh/python-redux/'
28+
documentation = 'https://github.com/sassanh/python-redux/'
29+
changelog = 'https://github.com/sassanh/python-redux/blob/main/CHANGELOG.md'
30+
2331
[build-system]
2432
requires = ["hatchling", "hatch-vcs"]
2533
build-backend = "hatchling.build"
@@ -39,10 +47,6 @@ packages = ["redux", "redux_pytest"]
3947
[tool.hatch.build.targets.sdist]
4048
packages = ["redux", "redux_pytest"]
4149

42-
[[project.authors]]
43-
name = "Sassan Haradji"
44-
email = "sassanh@gmail.com"
45-
4650
[project.scripts]
4751
demo = "demo:main"
4852
todo_demo = "todo_demo:main"

redux/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@
5555
'ReducerResult',
5656
'ReducerType',
5757
'Scheduler',
58+
'Store',
5859
'ViewDecorator',
5960
'ViewOptions',
6061
'ViewReturnType',
62+
'combine_reducers',
6163
'is_complete_reducer_result',
6264
'is_state_reducer_result',
63-
'combine_reducers',
64-
'Store',
6565
)

redux/basic_types.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class BaseEvent(Immutable): ...
4848
EventHandler = Callable[[Event], Any] | Callable[[], Any]
4949
AutorunArgs = ParamSpec('AutorunArgs')
5050
ViewArgs = ParamSpec('ViewArgs')
51+
Payload = TypeVar('Payload', bound=Any, default=None)
5152

5253

5354
class CompleteReducerResult(Immutable, Generic[State, Action, Event]):
@@ -302,13 +303,15 @@ class CombineReducerAction(BaseAction):
302303
_id: str
303304

304305

305-
class CombineReducerInitAction(CombineReducerAction, InitAction):
306+
class CombineReducerInitAction(CombineReducerAction, InitAction, Generic[Payload]):
306307
key: str
308+
payload: Payload | None = None
307309

308310

309-
class CombineReducerRegisterAction(CombineReducerAction):
311+
class CombineReducerRegisterAction(CombineReducerAction, Generic[Payload]):
310312
key: str
311313
reducer: ReducerType
314+
payload: Payload | None = None
312315

313316

314317
class CombineReducerUnregisterAction(CombineReducerAction):

redux/combine_reducers.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ def combined_reducer(
5555
result_actions = []
5656
result_events = []
5757
nonlocal state_class
58-
if state is not None and isinstance(action, CombineReducerAction):
59-
if isinstance(action, CombineReducerRegisterAction) and action._id == _id: # noqa: SLF001
58+
if (
59+
state is not None
60+
and isinstance(action, CombineReducerAction)
61+
and action._id == _id # noqa: SLF001
62+
):
63+
if isinstance(action, CombineReducerRegisterAction):
6064
key = action.key
6165
reducer = action.reducer
6266
reducers[key] = reducer
@@ -66,7 +70,7 @@ def combined_reducer(
6670
)
6771
reducer_result = reducer(
6872
None,
69-
CombineReducerInitAction(_id=_id, key=key),
73+
CombineReducerInitAction(_id=_id, key=key, payload=action.payload),
7074
)
7175
state = state_class(
7276
_id=state._id, # noqa: SLF001
@@ -93,9 +97,7 @@ def combined_reducer(
9397
if is_complete_reducer_result(reducer_result)
9498
else []
9599
)
96-
elif (
97-
isinstance(action, CombineReducerUnregisterAction) and action._id == _id # noqa: SLF001
98-
):
100+
elif isinstance(action, CombineReducerUnregisterAction):
99101
key = action.key
100102

101103
del reducers[key]

redux_pytest/fixtures/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
'LoopThread',
2121
'StoreMonitor',
2222
'StoreSnapshot',
23-
'Waiter',
2423
'WaitFor',
24+
'Waiter',
2525
'event_loop',
2626
'needs_finish',
2727
'snapshot_prefix',

0 commit comments

Comments
 (0)