Skip to content

Commit a4d3211

Browse files
committed
Extract buildConnectOptions out of connect()... will make testing easier
1 parent a6d82f0 commit a4d3211

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/connect/connect.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ import defaultSelectorFactory from './selectorFactory'
2020
The resulting final props selector is called by the Connect component instance whenever
2121
it receives new props or store state.
2222
*/
23-
export default function connect(
23+
24+
function match(arg, factories) {
25+
for (let i = factories.length - 1; i >= 0; i--) {
26+
const result = factories[i](arg)
27+
if (result) return result
28+
}
29+
return undefined
30+
}
31+
32+
export function buildConnectOptions(
2433
mapStateToProps,
2534
mapDispatchToProps,
2635
mergeProps,
@@ -46,7 +55,7 @@ export default function connect(
4655
const initMapDispatchToProps = match(mapDispatchToProps, mapDispatchToPropsFactories)
4756
const initMergeProps = match(mergeProps, mergePropsFactories)
4857

49-
return connectAdvanced(selectorFactory, {
58+
return {
5059
// used in error messages
5160
methodName: 'connect',
5261

@@ -57,20 +66,18 @@ export default function connect(
5766
shouldHandleStateChanges: Boolean(mapStateToProps),
5867

5968
// passed through to selectorFactory
69+
selectorFactory,
6070
initMapStateToProps,
6171
initMapDispatchToProps,
6272
initMergeProps,
6373
pure,
6474

6575
// any addional options args can override defaults of connect or connectAdvanced
6676
...options
67-
})
77+
}
6878
}
6979

70-
function match(arg, factories) {
71-
for (let i = factories.length - 1; i >= 0; i--) {
72-
const result = factories[i](arg)
73-
if (result) return result
74-
}
75-
return undefined
80+
export default function connect(...args) {
81+
const options = buildConnectOptions(...args)
82+
return connectAdvanced(options.selectorFactory, options)
7683
}

0 commit comments

Comments
 (0)