Add onDecorated property to decorated components (#1680)

This commit is contained in:
CHaBou 2017-03-28 02:07:55 +02:00 committed by Guillermo Rauch
parent 6f2a77f655
commit 7a64c9ee8a

View file

@ -370,9 +370,27 @@ export const middleware = store => next => action => {
nextMiddleware(middlewares)(action);
};
// expose decorated component instance to the higher-order components
function exposeDecorated(Component) {
return class extends React.Component {
constructor(props, context) {
super(props, context);
this.onRef = this.onRef.bind(this);
}
onRef(decorated) {
if (this.props.onDecorated) {
this.props.onDecorated(decorated);
}
}
render() {
return React.createElement(Component, Object.assign({}, this.props, {ref: this.onRef}));
}
};
}
function getDecorated(parent, name) {
if (!decorated[name]) {
let class_ = parent;
let class_ = exposeDecorated(parent);
modules.forEach(mod => {
const method = 'decorate' + name;