Skip to content

Commit

Permalink
Merge pull request #176 from ipanasenko/accept-thenable
Browse files Browse the repository at this point in the history
Add ability to accept thenables in identity requests
  • Loading branch information
ryanbrainard authored Jul 5, 2017
2 parents 2cda389 + c3e3c74 commit d36d6bd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ connect(props => ({

Note, this form of transformation is similar to what is possible on the `PromiseState` (i.e. `this.props.usersFetch.then(users => users.filter(u => u.verified))`); however, this has the advantage of only being called when `usersFetch` changes and keeps the logic out of the component.

Identity requests can also be provided a `Promise`. In this case, the `PromiseState` will be `pending` until the `Promise` is resolved. This can be helpful for asynchronous, non-fetch operations (e.g. file i/o) that want to use a similar pattern as fetch operations.
**Identity requests can also be provided a `Promise` or thenable.** In this case, the `PromiseState` will be `pending` until the `Promise` is resolved. This can be helpful for asynchronous, non-fetch operations (e.g. file i/o) that want to use a similar pattern as fetch operations.

## Accessing Headers & Metadata

Expand Down
3 changes: 2 additions & 1 deletion src/components/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import PromiseState from '../PromiseState'
import hoistStatics from 'hoist-non-react-statics'
import invariant from 'invariant'
import warning from 'warning'
import hasIn from 'lodash/hasIn'
import omit from 'lodash/fp/omit'

const defaultMapPropsToRequestsToProps = () => ({})
Expand Down Expand Up @@ -272,7 +273,7 @@ function connect(mapPropsToRequestsToProps, defaults, options) {
const onRejection = this.createPromiseStateOnRejection(prop, mapping, startedAt)

if (mapping.hasOwnProperty('value')) {
if (mapping.value instanceof Promise) {
if (hasIn(mapping.value, 'then')) {
this.setAtomicState(prop, startedAt, mapping, initPS(meta))
return mapping.value.then(onFulfillment(meta), onRejection(meta))
} else {
Expand Down

0 comments on commit d36d6bd

Please sign in to comment.