Skip to content

Commit f31b5d6

Browse files
committed
add: extend and improve API
1 parent 16c441e commit f31b5d6

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "onli-reducer",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "One line reducer. Simple state management without boilerplate.",
55
"main": "src/index.js",
66
"scripts": {

src/index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
const onliReducer = (dispatch, types) => {
2-
const newDispatch = type => action => dispatch({ type, ...action })
3-
const send = types.reduce(
4-
(acc, next) => ({ ...acc, [next]: newDispatch(next) }),
5-
{}
6-
)
1+
import onliReducer from "./onli-reducer"
2+
import onliTypes from "./onli-types"
3+
import onliSend from "./onli-send"
74

8-
return send
9-
}
5+
const onli = actions => [onliReducer(actions), onliTypes(actions)]
106

11-
export default onliReducer
7+
export { onliReducer, onliTypes, onliSend }
8+
export default onli

src/onli-reducer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default actions => (state, action) => actions[action.type](state, action)

src/onli-send.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default (dispatch, types) => {
2+
const newDispatch = type => action => dispatch({ type, ...action })
3+
const send = types.reduce(
4+
(acc, next) => ({ ...acc, [next]: newDispatch(next) }),
5+
{}
6+
)
7+
8+
return send
9+
}

src/onli-types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default actions => Object.keys(actions)

0 commit comments

Comments
 (0)