Skip to content

Commit

Permalink
Add combineReducers
Browse files Browse the repository at this point in the history
  • Loading branch information
stasm committed Sep 20, 2017
1 parent 3e32382 commit 0525054
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@

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

- Add an optional `combineReducers` module.

The `combineReducers` function can be used to hand off state changes to
smaller reducers. Each reducer takes care of one sub-tree of the state and
doesn't have access to the other parts.

`combineReducers` takes an object of `{name: reducer}` as the only
argument. The keys of the object will be used as top-level names in the
resulting state tree and the values will be set to the return values of
each of the reducers.


## 0.1.1 (September 12, 2017)

Expand Down
10 changes: 10 additions & 0 deletions combineReducers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default function combineReducers(reducers) {
return function(state = {}, action, args) {
return Object.entries(reducers).reduce(
(acc, [name, reducer]) => Object.assign(acc, {
[name]: reducer(state[name], action, args),
}),
state
);
}
}

0 comments on commit 0525054

Please sign in to comment.