Skip to content

Commit

Permalink
add: extend and improve API
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdouglas committed Aug 29, 2019
1 parent 16c441e commit f31b5d6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "onli-reducer",
"version": "0.0.2",
"version": "0.1.0",
"description": "One line reducer. Simple state management without boilerplate.",
"main": "src/index.js",
"scripts": {
Expand Down
15 changes: 6 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
const onliReducer = (dispatch, types) => {
const newDispatch = type => action => dispatch({ type, ...action })
const send = types.reduce(
(acc, next) => ({ ...acc, [next]: newDispatch(next) }),
{}
)
import onliReducer from "./onli-reducer"
import onliTypes from "./onli-types"
import onliSend from "./onli-send"

return send
}
const onli = actions => [onliReducer(actions), onliTypes(actions)]

export default onliReducer
export { onliReducer, onliTypes, onliSend }
export default onli
1 change: 1 addition & 0 deletions src/onli-reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default actions => (state, action) => actions[action.type](state, action)
9 changes: 9 additions & 0 deletions src/onli-send.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default (dispatch, types) => {
const newDispatch = type => action => dispatch({ type, ...action })
const send = types.reduce(
(acc, next) => ({ ...acc, [next]: newDispatch(next) }),
{}
)

return send
}
1 change: 1 addition & 0 deletions src/onli-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default actions => Object.keys(actions)

0 comments on commit f31b5d6

Please sign in to comment.