Skip to content

Commit a2887ae

Browse files
committed
Merge pull request #49 from vslinko/next-perform
Simplify perform API
2 parents 4c9dc62 + dddfe47 commit a2887ae

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

examples/actions/CounterActions.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ export function increment() {
77
}
88

99
export function incrementIfOdd() {
10-
return (dispatch, { counter }) => {
10+
return (perform, { counter }) => {
1111
if (counter % 2 === 0) {
1212
return;
1313
}
1414

15-
dispatch(increment());
15+
perform(increment());
1616
};
1717
}
1818

1919
export function incrementAsync() {
20-
return dispatch => {
20+
return perform => {
2121
setTimeout(() => {
22-
dispatch(increment());
22+
perform(increment());
2323
}, 1000);
2424
};
2525
}

src/Dispatcher.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ export default class Dispatcher {
2626
this.setAtom(nextAtom);
2727
}
2828

29-
perform(actionCreator, ...args) {
30-
const action = actionCreator(...args);
31-
29+
perform(action) {
3230
return typeof action === 'function'
3331
? action(this.dispatch, this.atom)
3432
: this.dispatch(action);

src/utils/bindActions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import mapValues from 'lodash/object/mapValues';
22

33
export default function bindActions(actionCreators, dispatcher) {
44
return mapValues(actionCreators, actionCreator =>
5-
(...args) => dispatcher.perform(actionCreator, ...args)
5+
(...args) => dispatcher.perform(actionCreator(...args))
66
);
77
}

0 commit comments

Comments
 (0)