Skip to content

Commit

Permalink
Merge pull request tajo#47 from MrOrz/master
Browse files Browse the repository at this point in the history
Avoid calling .bind() in render() and simplify openPortal()
  • Loading branch information
tajo committed Jan 21, 2016
2 parents 773fd5c + 94c0506 commit 276ddb9
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 @@ -91,17 +91,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 276ddb9

Please sign in to comment.