Skip to content

Commit

Permalink
unify handling with value & fetch request
Browse files Browse the repository at this point in the history
  • Loading branch information
Ville Saukkonen committed May 30, 2018
1 parent cce4a36 commit 43a4ba6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/components/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,7 @@ function connect(mapPropsToRequestsToProps, defaults, options) {
const onRejection = this.createPromiseStateOnRejection(prop, mapping, startedAt)

if (mapping.hasOwnProperty('value')) {
if (hasIn(mapping.value, 'then')) {
this.setAtomicState(prop, startedAt, mapping, initPS(meta))
return mapping.value.then(onFulfillment(meta), onRejection(meta))
} else {
return onFulfillment(meta)(mapping.value)
}
return onFulfillment(meta)(mapping.value)
} else {
const request = mapping.buildRequest(mapping)
meta.request = request
Expand Down
30 changes: 30 additions & 0 deletions test/components/connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,36 @@ describe('React', () => {
})
})

it('should call then mappings with meta.component with value', (done) => {
const thenSpy = expect.createSpy()
const connectWithRef = connect.options({ withRef: true })

class Container extends Component {
render() {
return <Passthrough {...this.props} />
}
}

const DecoratedContainer = connectWithRef(() => ({
someFetch: {
value: { random: 'value' },
then: thenSpy
}
}))(Container)

const decoratedContainer = TestUtils.renderIntoDocument(
<DecoratedContainer/>
)

const container = TestUtils.findRenderedComponentWithType(decoratedContainer, Container)

setImmediate(() => {
const meta = thenSpy.calls[0].arguments[1]
expect(thenSpy.calls[0]).toEqual(123)
done()
})
})

it('should call catch mappings', (done) => {
const props = ({
baz: 42
Expand Down

0 comments on commit 43a4ba6

Please sign in to comment.