From 86febf27d49667e8d2e6fca17dbbd14379f79edf Mon Sep 17 00:00:00 2001 From: Tomasz Sok Date: Thu, 15 Sep 2016 15:22:55 -0500 Subject: [PATCH] Rename componentDidUnmount & move bind call to constructors (#54) * Rename componentDidUnmount to componentWillUnmount * Move .bind(this) call to constructor in a few components Closes #34. --- src/components/App.js | 2 +- src/components/ChromeNotice.js | 4 ++-- src/components/DownloadButton.js | 6 ++++- src/components/DownloadPage.js | 6 +++-- src/components/DropZone.js | 13 +++++++---- src/components/ErrorPage.js | 2 +- src/components/Tempalink.js | 6 ++++- src/components/UploadPage.js | 40 +++++++++++++++++--------------- src/components/Uploader.js | 6 ++++- 9 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/components/App.js b/src/components/App.js index 2bb955e..fbda4cd 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -24,7 +24,7 @@ export default class App extends React.Component { SupportStore.listen(this._onChange) } - componentDidUnmount() { + componentWillUnmount() { SupportStore.unlisten(this._onChange) } diff --git a/src/components/ChromeNotice.js b/src/components/ChromeNotice.js index cc5fd66..4bd03ab 100644 --- a/src/components/ChromeNotice.js +++ b/src/components/ChromeNotice.js @@ -4,7 +4,7 @@ import SupportStore from '../stores/SupportStore' function getState() { return { - active: SupportStore.getState().isChrome && DownloadStore.getState().fileSize >= 500000000 + active: SupportStore.getState().isChrome && DownloadStore.getState().fileSize >= 500000000 } } @@ -24,7 +24,7 @@ export default class ChromeNotice extends React.Component { SupportStore.listen(this._onChange) } - componentDidUnmount() { + componentWillUnmount() { DownloadStore.unlisten(this._onChange) SupportStore.unlisten(this._onChange) } diff --git a/src/components/DownloadButton.js b/src/components/DownloadButton.js index 2a3e16c..20a6494 100644 --- a/src/components/DownloadButton.js +++ b/src/components/DownloadButton.js @@ -1,6 +1,10 @@ import React from 'react' export default class DownloadButton extends React.Component { + constructor() { + super() + this.onClick = this.onClick.bind(this) + } onClick(e) { this.props.onClick(e) @@ -9,7 +13,7 @@ export default class DownloadButton extends React.Component { render() { return } diff --git a/src/components/DownloadPage.js b/src/components/DownloadPage.js index 5b02e12..8279246 100644 --- a/src/components/DownloadPage.js +++ b/src/components/DownloadPage.js @@ -17,13 +17,15 @@ export default class DownloadPage extends React.Component { this._onChange = () => { this.setState(DownloadStore.getState()) } + + this.downloadFile = this.downloadFile.bind(this) } componentDidMount() { DownloadStore.listen(this._onChange) } - componentDidUnmount() { + componentWillUnmount() { DownloadStore.unlisten(this._onChange) } @@ -43,7 +45,7 @@ export default class DownloadPage extends React.Component {

Peers: {this.state.peers} · Up: {formatSize(this.state.speedUp)} · Down: {formatSize(this.state.speedDown)}

- + diff --git a/src/components/DropZone.js b/src/components/DropZone.js index 33e3f99..538b447 100644 --- a/src/components/DropZone.js +++ b/src/components/DropZone.js @@ -5,6 +5,11 @@ export default class DropZone extends React.Component { constructor() { super() 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() { @@ -31,10 +36,10 @@ export default class DropZone extends React.Component { render() { return
+ onDragEnter={this.onDragEnter} + onDragLeave={this.onDragLeave} + onDragOver={this.onDragOver} + onDrop={this.onDrop}>