From a37f2d335a7a5c3d8bddfe77bd8a1a9c0c4f194d Mon Sep 17 00:00:00 2001 From: Elad Ossadon Date: Mon, 25 Jan 2016 19:03:22 -0800 Subject: [PATCH] use hoist-non-react-methods and copy wrapped component methods into the wrapper component --- package.json | 2 +- src/components/connect.js | 4 ++-- test/components/connect.spec.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 9b95d86f8..8c264c0f4 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "webpack": "^1.11.0" }, "dependencies": { - "hoist-non-react-statics": "^1.0.3", + "hoist-non-react-methods": "^1.0.2", "invariant": "^2.0.0" }, "peerDependencies": { diff --git a/src/components/connect.js b/src/components/connect.js index e9fbc06e5..ec7f2474c 100644 --- a/src/components/connect.js +++ b/src/components/connect.js @@ -3,8 +3,8 @@ const storeShape = require('../utils/storeShape') const shallowEqual = require('../utils/shallowEqual') const isPlainObject = require('../utils/isPlainObject') const wrapActionCreators = require('../utils/wrapActionCreators') -const hoistStatics = require('hoist-non-react-statics') const invariant = require('invariant') +import hoistMethods from 'hoist-non-react-methods' const defaultMapStateToProps = state => ({}) // eslint-disable-line no-unused-vars const defaultMapDispatchToProps = dispatch => ({ dispatch }) @@ -270,7 +270,7 @@ function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) } } - return hoistStatics(Connect, WrappedComponent) + return hoistMethods(Connect, WrappedComponent, w => w.getWrappedInstance()) } } diff --git a/test/components/connect.spec.js b/test/components/connect.spec.js index 5fefb76da..043b3ce81 100644 --- a/test/components/connect.spec.js +++ b/test/components/connect.spec.js @@ -1267,7 +1267,7 @@ describe('React', () => { ) }) - it('should return the instance of the wrapped component for use in calling child methods', () => { + it('should return the instance of the wrapped component with its child custom methods', () => { const store = createStore(() => ({})) const someData = { @@ -1295,7 +1295,7 @@ describe('React', () => { const decorated = TestUtils.findRenderedComponentWithType(tree, Decorated) - expect(() => decorated.someInstanceMethod()).toThrow() + expect(decorated.someInstanceMethod()).toBe(someData) expect(decorated.getWrappedInstance().someInstanceMethod()).toBe(someData) expect(decorated.refs.wrappedInstance.someInstanceMethod()).toBe(someData) })