From 1ec7c87001c39cca4b784bf97972280fd965efb3 Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Thu, 25 May 2017 00:55:16 +0900 Subject: [PATCH] Remove unnecessary constructors (#3280) --- app/javascript/mastodon/components/account.js | 13 ++------ .../components/autosuggest_textarea.js | 33 +++++++------------ .../features/ui/components/boost_modal.js | 6 ---- 3 files changed, 15 insertions(+), 37 deletions(-) diff --git a/app/javascript/mastodon/components/account.js b/app/javascript/mastodon/components/account.js index baac734aa..9d65af46c 100644 --- a/app/javascript/mastodon/components/account.js +++ b/app/javascript/mastodon/components/account.js @@ -27,22 +27,15 @@ class Account extends ImmutablePureComponent { intl: PropTypes.object.isRequired, }; - constructor (props, context) { - super(props, context); - this.handleFollow = this.handleFollow.bind(this); - this.handleBlock = this.handleBlock.bind(this); - this.handleMute = this.handleMute.bind(this); - } - - handleFollow () { + handleFollow = () => { this.props.onFollow(this.props.account); } - handleBlock () { + handleBlock = () => { this.props.onBlock(this.props.account); } - handleMute () { + handleMute = () => { this.props.onMute(this.props.account); } diff --git a/app/javascript/mastodon/components/autosuggest_textarea.js b/app/javascript/mastodon/components/autosuggest_textarea.js index 0a9af5126..9372e6146 100644 --- a/app/javascript/mastodon/components/autosuggest_textarea.js +++ b/app/javascript/mastodon/components/autosuggest_textarea.js @@ -51,23 +51,14 @@ class AutosuggestTextarea extends ImmutablePureComponent { autoFocus: true, }; - constructor (props, context) { - super(props, context); - this.state = { - suggestionsHidden: false, - selectedSuggestion: 0, - lastToken: null, - tokenStart: 0, - }; - this.onChange = this.onChange.bind(this); - this.onKeyDown = this.onKeyDown.bind(this); - this.onBlur = this.onBlur.bind(this); - this.onSuggestionClick = this.onSuggestionClick.bind(this); - this.setTextarea = this.setTextarea.bind(this); - this.onPaste = this.onPaste.bind(this); - } + state = { + suggestionsHidden: false, + selectedSuggestion: 0, + lastToken: null, + tokenStart: 0, + }; - onChange (e) { + onChange = (e) => { const [ tokenStart, token ] = textAtCursorMatchesToken(e.target.value, e.target.selectionStart); if (token !== null && this.state.lastToken !== token) { @@ -85,7 +76,7 @@ class AutosuggestTextarea extends ImmutablePureComponent { this.props.onChange(e); } - onKeyDown (e) { + onKeyDown = (e) => { const { suggestions, disabled } = this.props; const { selectedSuggestion, suggestionsHidden } = this.state; @@ -135,7 +126,7 @@ class AutosuggestTextarea extends ImmutablePureComponent { this.props.onKeyDown(e); } - onBlur () { + onBlur = () => { // If we hide the suggestions immediately, then this will prevent the // onClick for the suggestions themselves from firing. // Setting a short window for that to take place before hiding the @@ -145,7 +136,7 @@ class AutosuggestTextarea extends ImmutablePureComponent { }, 100); } - onSuggestionClick (e) { + onSuggestionClick = (e) => { const suggestion = Number(e.currentTarget.getAttribute('data-index')); e.preventDefault(); this.props.onSuggestionSelected(this.state.tokenStart, this.state.lastToken, suggestion); @@ -158,11 +149,11 @@ class AutosuggestTextarea extends ImmutablePureComponent { } } - setTextarea (c) { + setTextarea = (c) => { this.textarea = c; } - onPaste (e) { + onPaste = (e) => { if (e.clipboardData && e.clipboardData.files.length === 1) { this.props.onPaste(e.clipboardData.files); e.preventDefault(); diff --git a/app/javascript/mastodon/features/ui/components/boost_modal.js b/app/javascript/mastodon/features/ui/components/boost_modal.js index fc6b37095..183f05fab 100644 --- a/app/javascript/mastodon/features/ui/components/boost_modal.js +++ b/app/javascript/mastodon/features/ui/components/boost_modal.js @@ -27,12 +27,6 @@ class BoostModal extends ImmutablePureComponent { intl: PropTypes.object.isRequired, }; - constructor (props, context) { - super(props, context); - this.handleReblog = this.handleReblog.bind(this); - this.handleAccountClick = this.handleAccountClick.bind(this); - } - handleReblog = () => { this.props.onReblog(this.props.status); this.props.onClose();