From 54dc59b1035b87196542d14f842013461add3266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codon=CC=83er?= Date: Mon, 2 Apr 2018 11:55:42 +0200 Subject: [PATCH] implement ref as an option --- src/compose.js | 13 +++++++++---- src/tests/compose.js | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/compose.js b/src/compose.js index 8cce3fa..ef79ba1 100644 --- a/src/compose.js +++ b/src/compose.js @@ -14,6 +14,7 @@ export default function compose(dataLoader, options = {}) { propsToWatch = null, // Watch all the props. shouldSubscribe = null, shouldUpdate = null, + withRef = false, } = options; class Container extends React.Component { @@ -119,12 +120,16 @@ export default function compose(dataLoader, options = {}) { ...data, }; - const setChildRef = (c) => { - this.child = c; - }; + const refs = {}; + if (withRef) { + const setChildRef = (c) => { + this.child = c; + }; + refs.ref = setChildRef; + } return ( - + ); } } diff --git a/src/tests/compose.js b/src/tests/compose.js index d2e9aa0..ec3abdd 100644 --- a/src/tests/compose.js +++ b/src/tests/compose.js @@ -72,9 +72,10 @@ describe('compose', () => { }); it('should set the child ref', () => { + const options = { withRef: true }; const Container = compose((props, onData) => { onData(null, { name: 'arunoda' }); - })(Comp); + }, options)(Comp); const el = mount(); expect(el.instance().child.props.name).to.be.equal('arunoda'); });