Skip to content

Commit 43a4ba6

Browse files
author
Ville Saukkonen
committed
unify handling with value & fetch request
1 parent cce4a36 commit 43a4ba6

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/components/connect.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,7 @@ function connect(mapPropsToRequestsToProps, defaults, options) {
274274
const onRejection = this.createPromiseStateOnRejection(prop, mapping, startedAt)
275275

276276
if (mapping.hasOwnProperty('value')) {
277-
if (hasIn(mapping.value, 'then')) {
278-
this.setAtomicState(prop, startedAt, mapping, initPS(meta))
279-
return mapping.value.then(onFulfillment(meta), onRejection(meta))
280-
} else {
281-
return onFulfillment(meta)(mapping.value)
282-
}
277+
return onFulfillment(meta)(mapping.value)
283278
} else {
284279
const request = mapping.buildRequest(mapping)
285280
meta.request = request

test/components/connect.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,36 @@ describe('React', () => {
590590
})
591591
})
592592

593+
it('should call then mappings with meta.component with value', (done) => {
594+
const thenSpy = expect.createSpy()
595+
const connectWithRef = connect.options({ withRef: true })
596+
597+
class Container extends Component {
598+
render() {
599+
return <Passthrough {...this.props} />
600+
}
601+
}
602+
603+
const DecoratedContainer = connectWithRef(() => ({
604+
someFetch: {
605+
value: { random: 'value' },
606+
then: thenSpy
607+
}
608+
}))(Container)
609+
610+
const decoratedContainer = TestUtils.renderIntoDocument(
611+
<DecoratedContainer/>
612+
)
613+
614+
const container = TestUtils.findRenderedComponentWithType(decoratedContainer, Container)
615+
616+
setImmediate(() => {
617+
const meta = thenSpy.calls[0].arguments[1]
618+
expect(thenSpy.calls[0]).toEqual(123)
619+
done()
620+
})
621+
})
622+
593623
it('should call catch mappings', (done) => {
594624
const props = ({
595625
baz: 42

0 commit comments

Comments
 (0)