Skip to content

Commit

Permalink
Add onDecorated property to decorated components (#1680)
Browse files Browse the repository at this point in the history
  • Loading branch information
chabou authored and rauchg committed Mar 28, 2017
1 parent 6f2a77f commit 7a64c9e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/utils/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7a64c9e

Please sign in to comment.