connect-alt
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -0,1 +1,7 @@ | ||
### v1.0.7 | ||
* provide a way to access to the DecoratedComponent instance (d64b703) | ||
* copy correct displayName from decorated component (7e87b60) | ||
* fixes an issue where props where incorrect on DecoratedComponent on initialization (fe5c762) | ||
## v1.0.6 | ||
@@ -2,0 +8,0 @@ |
@@ -33,2 +33,8 @@ 'use strict'; | ||
// borrowed from `react-redux/connect` | ||
// https://github.com/rackt/react-redux/blob/master/src/components/connect.js#L17 | ||
function getDisplayName(WrappedComponent) { | ||
return WrappedComponent.displayName || WrappedComponent.name || 'Component'; | ||
} | ||
function connectToStores(reducer) { | ||
@@ -62,2 +68,6 @@ return function (DecoratedComponent) { | ||
flux.FinalStore.listen(this.handleStoresChange); | ||
// a store update may have been updated between state | ||
// initialization and listening for changes from store | ||
return this.handleStoresChange(); | ||
} | ||
@@ -87,3 +97,5 @@ }, { | ||
return _react2['default'].createElement(DecoratedComponent, _extends({}, this.props, customProps)); | ||
return _react2['default'].createElement(DecoratedComponent, _extends({ | ||
ref: 'decoratedComponent' | ||
}, this.props, customProps)); | ||
} | ||
@@ -94,2 +106,6 @@ }], [{ | ||
enumerable: true | ||
}, { | ||
key: 'displayName', | ||
value: 'Connect(' + getDisplayName(DecoratedComponent) + ')', | ||
enumerable: true | ||
}]); | ||
@@ -96,0 +112,0 @@ |
{ | ||
"name": "connect-alt", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Decorator for passing Altjs store state through props", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
@@ -8,6 +8,14 @@ import React, { PropTypes } from 'react'; | ||
// borrowed from `react-redux/connect` | ||
// https://github.com/rackt/react-redux/blob/master/src/components/connect.js#L17 | ||
function getDisplayName(WrappedComponent) { | ||
return WrappedComponent.displayName || WrappedComponent.name || 'Component' | ||
} | ||
export default function connectToStores(reducer) { | ||
return function(DecoratedComponent) { | ||
class ConnectToStoresWrapper extends PureComponent { | ||
static contextTypes = { flux: PropTypes.object.isRequired } | ||
static displayName = `Connect(${getDisplayName(DecoratedComponent)})` | ||
@@ -19,2 +27,6 @@ state = { customProps: reducer(this.takeSnapshot()) }; | ||
flux.FinalStore.listen(this.handleStoresChange); | ||
// a store update may have been updated between state | ||
// initialization and listening for changes from store | ||
return this.handleStoresChange(); | ||
} | ||
@@ -38,8 +50,14 @@ | ||
handleStoresChange = () => | ||
this.setState({ customProps: reducer(this.takeSnapshot()) }) | ||
handleStoresChange = () => { | ||
return this.setState({ customProps: reducer(this.takeSnapshot()) }); | ||
} | ||
render() { | ||
const { customProps } = this.state; | ||
return (<DecoratedComponent { ...this.props } { ...customProps } />); | ||
return ( | ||
<DecoratedComponent | ||
ref='decoratedComponent' | ||
{ ...this.props } | ||
{ ...customProps } /> | ||
); | ||
} | ||
@@ -46,0 +64,0 @@ } |
12447
186