Skip to content
This repository was archived by the owner on Nov 23, 2020. It is now read-only.

Commit 2de67ef

Browse files
author
Vince Speelman
committed
feat(creators): unwrap functions which return promises
often, you'll want to pass some data to your promise, and it wont be prepared with partial application in mind. Now, we can support that by checking the return value. BREAKING CHANGE: functions that return promises are now treated as async
1 parent 2bf1c77 commit 2de67ef

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { createActions as act } from 'redux-actions';
22

33
const STATES = ['REQUESTED', 'RECEIVED', 'REJECTED'];
4-
const isPromise = value => Promise.resolve(value) === value;
4+
const isPromise = value => {
5+
let test = value;
6+
if (typeof value === 'function') {
7+
test = value();
8+
}
9+
return Promise.resolve(test) === test;
10+
};
511

612
const createActions = (
713
{ states = STATES, prefix = '' } = {

src/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ca from './';
22

33
const DEFAULT_MOCK = ca()()({
44
PROFILE: new Promise(res => res('profile')),
5-
REGISTRATION: new Promise(res => res('registered')),
5+
REGISTRATION: login => new Promise(res => res('registered', login)),
66
EXPLORE_STATUS: () => 'status',
77
FOO: undefined,
88
});

0 commit comments

Comments
 (0)