Skip to content

Commit

Permalink
Avoid calling .bind() in render() and simplify openPortal()
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Jan 20, 2016
1 parent 8bb0ca1 commit 94c0506
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class Portal extends React.Component {
constructor() {
super();
this.state = {active: false};
this.openPortal = this.openPortal.bind(this);
this.handleWrapperClick = this.handleWrapperClick.bind(this);
this.closePortal = this.closePortal.bind(this);
this.handleOutsideMouseClick = this.handleOutsideMouseClick.bind(this);
this.handleKeydown = this.handleKeydown.bind(this);
Expand All @@ -31,7 +31,7 @@ export default class Portal extends React.Component {
}

if (this.props.isOpened) {
this.openPortal(this.props);
this.openPortal();
}
}

Expand Down Expand Up @@ -89,17 +89,19 @@ export default class Portal extends React.Component {

render() {
if (this.props.openByClickOn) {
return <div className="openByClickOn" onClick={this.openPortal.bind(this, this.props)}>{this.props.openByClickOn}</div>;
return <div className="openByClickOn" onClick={this.handleWrapperClick}>{this.props.openByClickOn}</div>;
} else {
return null;
}
}

openPortal(props, e) {
if (e) {
e.preventDefault();
e.stopPropagation();
}
handleWrapperClick(e) {
e.preventDefault();
e.stopPropagation();
this.openPortal();
}

openPortal(props = this.props) {
this.setState({active: true});
this.renderPortal(props);

Expand Down

0 comments on commit 94c0506

Please sign in to comment.