Skip to content

Commit

Permalink
Merge pull request #15 from tomatau/fulfilledMeta
Browse files Browse the repository at this point in the history
Add customisable payload for promise resolution to fulfilled action
  • Loading branch information
Patrick Burtchaell committed Nov 3, 2015
2 parents 4a3908e + a24112d commit b3448ed
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,26 @@ export default function promiseMiddleware(config={}) {
next({
type: `${type}_${PENDING}`,
payload: data,
...meta ? { meta } : {}
...meta && { meta }
});

/**
* Return either the fulfilled action object or the rejected
* action object.
*/
return promise.then(
payload => next({ // eslint-disable-line no-shadow
payload,
resolved => next({ // eslint-disable-line no-shadow
type: `${type}_${FULFILLED}`,
...meta ? { meta } : {}
...resolved.meta || resolved.payload ? resolved : {
payload: resolved,
...meta && { meta }
}
}),
error => next({
type: `${type}_${REJECTED}`,
payload: error,
error: true,
type: `${type}_${REJECTED}`,
...meta ? { meta } : {}
...meta && { meta }
})
);
};
Expand Down

0 comments on commit b3448ed

Please sign in to comment.