Merge pull request #2 from tomsapps/move-bind-function

Move .bind(this) call to constructor in a few components
pull/54/head
Tomasz Sok 9 years ago committed by GitHub
commit e0edef134f

@ -1,6 +1,10 @@
import React from 'react' import React from 'react'
export default class DownloadButton extends React.Component { export default class DownloadButton extends React.Component {
constructor() {
super()
this.onClick = this.onClick.bind(this)
}
onClick(e) { onClick(e) {
this.props.onClick(e) this.props.onClick(e)
@ -9,7 +13,7 @@ export default class DownloadButton extends React.Component {
render() { render() {
return <button return <button
className="download-button" className="download-button"
onClick={this.onClick.bind(this)}> onClick={this.onClick}>
Download Download
</button> </button>
} }

@ -17,6 +17,8 @@ export default class DownloadPage extends React.Component {
this._onChange = () => { this._onChange = () => {
this.setState(DownloadStore.getState()) this.setState(DownloadStore.getState())
} }
this.downloadFile = this.downloadFile.bind(this)
} }
componentDidMount() { componentDidMount() {
@ -43,7 +45,7 @@ export default class DownloadPage extends React.Component {
<ChromeNotice /> <ChromeNotice />
<p className="notice">Peers: {this.state.peers} &middot; Up: {formatSize(this.state.speedUp)} &middot; Down: {formatSize(this.state.speedDown)}</p> <p className="notice">Peers: {this.state.peers} &middot; Up: {formatSize(this.state.speedUp)} &middot; Down: {formatSize(this.state.speedDown)}</p>
<DownloadButton onClick={this.downloadFile.bind(this)} /> <DownloadButton onClick={this.downloadFile} />
</div> </div>

@ -5,6 +5,11 @@ export default class DropZone extends React.Component {
constructor() { constructor() {
super() super()
this.state = { focus: false } this.state = { focus: false }
this.onDragEnter = this.onDragEnter.bind(this)
this.onDragLeave = this.onDragLeave.bind(this)
this.onDragOver = this.onDragOver.bind(this)
this.onDrop = this.onDrop.bind(this)
} }
onDragEnter() { onDragEnter() {
@ -31,10 +36,10 @@ export default class DropZone extends React.Component {
render() { render() {
return <div className="drop-zone" ref="root" return <div className="drop-zone" ref="root"
onDragEnter={this.onDragEnter.bind(this)} onDragEnter={this.onDragEnter}
onDragLeave={this.onDragLeave.bind(this)} onDragLeave={this.onDragLeave}
onDragOver={this.onDragOver.bind(this)} onDragOver={this.onDragOver}
onDrop={this.onDrop.bind(this)}> onDrop={this.onDrop}>
<div className="drop-zone-overlay" <div className="drop-zone-overlay"
hidden={!this.state.focus} hidden={!this.state.focus}

@ -1,6 +1,10 @@
import React from 'react' import React from 'react'
export default class Tempalink extends React.Component { export default class Tempalink extends React.Component {
constructor() {
super()
this.onClick = this.onClick.bind(this)
}
onClick() { onClick() {
this.refs.input.getDOMNode().setSelectionRange(0, 9999) this.refs.input.getDOMNode().setSelectionRange(0, 9999)
@ -10,7 +14,7 @@ export default class Tempalink extends React.Component {
var url = window.location.origin + '/' + this.props.token var url = window.location.origin + '/' + this.props.token
return <input return <input
className="tempalink" className="tempalink"
onClick={this.onClick.bind(this)} onClick={this.onClick}
readOnly readOnly
ref="input" ref="input"
type="text" type="text"

@ -16,6 +16,8 @@ export default class UploadPage extends React.Component {
this._onChange = () => { this._onChange = () => {
this.setState(UploadStore.getState()) this.setState(UploadStore.getState())
} }
this.uploadFile = this.uploadFile.bind(this)
} }
componentDidMount() { componentDidMount() {
@ -25,7 +27,7 @@ export default class UploadPage extends React.Component {
componentWillUnmount() { componentWillUnmount() {
UploadStore.unlisten(this._onChange) UploadStore.unlisten(this._onChange)
} }
uploadFile(file) { uploadFile(file) {
UploadActions.uploadFile(file) UploadActions.uploadFile(file)
} }
@ -41,7 +43,7 @@ export default class UploadPage extends React.Component {
switch (this.state.status) { switch (this.state.status) {
case 'ready': case 'ready':
return <DropZone onDrop={this.uploadFile.bind(this)}> return <DropZone onDrop={this.uploadFile}>
<div className="page"> <div className="page">
<Spinner dir="up" /> <Spinner dir="up" />

@ -3,6 +3,10 @@ import React from 'react';
import UploadActions from '@app/actions/UploadActions'; import UploadActions from '@app/actions/UploadActions';
export default class UploadPage extends React.Component { export default class UploadPage extends React.Component {
constructor() {
super()
this.uploadFile = this.uploadFile.bind(this)
}
uploadFile(file) { uploadFile(file) {
UploadActions.uploadFile(file); UploadActions.uploadFile(file);
@ -12,7 +16,7 @@ export default class UploadPage extends React.Component {
switch (this.props.status) { switch (this.props.status) {
case 'ready': case 'ready':
return <div> return <div>
<DropZone onDrop={this.uploadFile.bind(this)} /> <DropZone onDrop={this.uploadFile} />
<Arrow dir="up" /> <Arrow dir="up" />
</div>; </div>;
break; break;

Loading…
Cancel
Save