Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@
"react-dom": "0.14.0",
"rimraf": "2.4.3",
"sinon": "1.17.1"
},
"dependencies": {
"hoist-non-react-statics": "^1.2.0"
}
}
7 changes: 7 additions & 0 deletions src/connectToStores.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
*/

import React from 'react'
import statics from 'hoist-non-react-statics'
import { assign, isFunction } from './functions'

function connectToStores(Spec, Component = Spec) {
Expand Down Expand Up @@ -107,6 +108,12 @@ function connectToStores(Spec, Component = Spec) {
StoreConnection.contextTypes = Component.contextTypes
}

statics(StoreConnection, Spec, {
getStores: true,
getPropsFromStores: true
})


return StoreConnection
}

Expand Down
32 changes: 32 additions & 0 deletions test/connect-to-stores-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,38 @@ export default {
assert.throws(() => connectToStores(BadComponentOne), 'expects the wrapped component to have a static getStores() method')
},

'static methods on wrapped component are copied to StoreConnection component'() {

let outsideFunction = sinon.spy();

const ComponentWithStatics = React.createClass({
statics: {
getStores() {
return [testStore]
},
getPropsFromStores(props) {
return testStore.getState()
},
foo() {
outsideFunction()
}
},
render() {
return React.createElement('div', null, 'statics')
}
})

const wrappedComponent = connectToStores(ComponentWithStatics)


assert.isFunction(wrappedComponent.foo, 'expects foo to also be a function on the wrapped component')
assert.isNotFunction(wrappedComponent.getPropsFromStores, 'expects getPropsFromStores to not be copied')
assert.isNotFunction(wrappedComponent.getStores, 'expects getStores to not be copied')

wrappedComponent.foo()
assert.strictEqual(outsideFunction.called, true, 'expects the function outside to have been called')
},

'element mounts and unmounts'() {
const div = document.createElement('div')

Expand Down