Skip to content

Commit ef09ba9

Browse files
committed
Add combineReducers
1 parent c7b2d60 commit ef09ba9

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@
3939

4040
html`${items.length > 0 && ItemList()}`
4141

42+
- Add an optional `combineReducers` module.
43+
44+
The `combineReducers` function can be used to hand off state changes to
45+
smaller reducers. Each reducer takes care of one sub-tree of the state and
46+
doesn't have access to the other parts.
47+
48+
`combineReducers` takes an object of `{name: reducer}` as the only
49+
argument. The keys of the object will be used as top-level names in the
50+
resulting state tree and the values will be set to the return values of
51+
each of the reducers.
52+
4253

4354
## 0.1.1 (September 12, 2017)
4455

combineReducers.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function combineReducers(reducers) {
2+
return function(state = {}, action, args) {
3+
return Object.entries(reducers).reduce(
4+
(acc, [name, reducer]) => Object.assign(acc, {
5+
[name]: reducer(state[name], action, args),
6+
}),
7+
state
8+
);
9+
}
10+
}

0 commit comments

Comments
 (0)