From 1c8d940b945d519f32011e1359bd65c42e5f83b1 Mon Sep 17 00:00:00 2001 From: Miguel Oller Date: Sun, 26 Jun 2016 20:15:52 -0400 Subject: [PATCH] Add connect enhancer --- src/components/connect.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/connect.js b/src/components/connect.js index 3b60ebbce..98dffd93b 100644 --- a/src/components/connect.js +++ b/src/components/connect.js @@ -32,7 +32,17 @@ function tryCatch(fn, ctx) { // Helps track hot reloading. let nextVersion = 0 -export default function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) { +export default function connect(...args) { + const [ mapStateToProps, mapDispatchToProps, mergeProps, { enhancer, ...options } = {} ] = args + + if (typeof enhancer !== 'undefined') { + if (typeof enhancer !== 'function') { + throw new Error('Expected the enhancer to be a function.') + } + + return enhancer(connect)(...args.slice(0, args.length - 1), options) + } + const shouldSubscribe = Boolean(mapStateToProps) const mapState = mapStateToProps || defaultMapStateToProps