convert manual bind to arrow

This commit is contained in:
Labhansh Agrawal 2019-11-25 21:46:00 +05:30 committed by Benjamin Staneck
parent ac782f382b
commit 4e0fc48ec6
11 changed files with 62 additions and 99 deletions

View file

@ -7,17 +7,7 @@ import Tabs_ from './tabs';
const Tabs = decorate(Tabs_, 'Tabs'); const Tabs = decorate(Tabs_, 'Tabs');
export default class Header extends React.PureComponent { export default class Header extends React.PureComponent {
constructor() { onChangeIntent = active => {
super();
this.onChangeIntent = this.onChangeIntent.bind(this);
this.handleHeaderMouseDown = this.handleHeaderMouseDown.bind(this);
this.handleHamburgerMenuClick = this.handleHamburgerMenuClick.bind(this);
this.handleMaximizeClick = this.handleMaximizeClick.bind(this);
this.handleMinimizeClick = this.handleMinimizeClick.bind(this);
this.handleCloseClick = this.handleCloseClick.bind(this);
}
onChangeIntent(active) {
// we ignore clicks if they're a byproduct of a drag // we ignore clicks if they're a byproduct of a drag
// motion to move the window // motion to move the window
if (window.screenX !== this.headerMouseDownWindowX || window.screenY !== this.headerMouseDownWindowY) { if (window.screenX !== this.headerMouseDownWindowX || window.screenY !== this.headerMouseDownWindowY) {
@ -25,9 +15,9 @@ export default class Header extends React.PureComponent {
} }
this.props.onChangeTab(active); this.props.onChangeTab(active);
} };
handleHeaderMouseDown() { handleHeaderMouseDown = () => {
// the hack of all hacks, this prevents the term // the hack of all hacks, this prevents the term
// iframe from losing focus, for example, when // iframe from losing focus, for example, when
// the user drags the nav around // the user drags the nav around
@ -38,30 +28,30 @@ export default class Header extends React.PureComponent {
// to differentiate dragging from clicking // to differentiate dragging from clicking
this.headerMouseDownWindowX = window.screenX; this.headerMouseDownWindowX = window.screenX;
this.headerMouseDownWindowY = window.screenY; this.headerMouseDownWindowY = window.screenY;
} };
handleHamburgerMenuClick(event) { handleHamburgerMenuClick = event => {
let {right: x, bottom: y} = event.currentTarget.getBoundingClientRect(); let {right: x, bottom: y} = event.currentTarget.getBoundingClientRect();
x -= 15; // to compensate padding x -= 15; // to compensate padding
y -= 12; // ^ same y -= 12; // ^ same
this.props.openHamburgerMenu({x, y}); this.props.openHamburgerMenu({x, y});
} };
handleMaximizeClick() { handleMaximizeClick = () => {
if (this.props.maximized) { if (this.props.maximized) {
this.props.unmaximize(); this.props.unmaximize();
} else { } else {
this.props.maximize(); this.props.maximize();
} }
} };
handleMinimizeClick() { handleMinimizeClick = () => {
this.props.minimize(); this.props.minimize();
} };
handleCloseClick() { handleCloseClick = () => {
this.props.close(); this.props.close();
} };
componentWillUnmount() { componentWillUnmount() {
delete this.clicks; delete this.clicks;

View file

@ -6,8 +6,6 @@ export default class Notification extends React.PureComponent {
this.state = { this.state = {
dismissing: false dismissing: false
}; };
this.handleDismiss = this.handleDismiss.bind(this);
this.onElement = this.onElement.bind(this);
} }
componentDidMount() { componentDidMount() {
@ -29,11 +27,11 @@ export default class Notification extends React.PureComponent {
} }
} }
handleDismiss() { handleDismiss = () => {
this.setState({dismissing: true}); this.setState({dismissing: true});
} };
onElement(el) { onElement = el => {
if (el) { if (el) {
el.addEventListener('webkitTransitionEnd', () => { el.addEventListener('webkitTransitionEnd', () => {
if (this.state.dismissing) { if (this.state.dismissing) {
@ -45,7 +43,7 @@ export default class Notification extends React.PureComponent {
el.style.setProperty('background-color', backgroundColor, 'important'); el.style.setProperty('background-color', backgroundColor, 'important');
} }
} }
} };
setDismissTimer() { setDismissTimer() {
this.dismissTimer = setTimeout(() => { this.dismissTimer = setTimeout(() => {

View file

@ -16,16 +16,15 @@ const enterKey = 13;
export default class SearchBox extends React.PureComponent { export default class SearchBox extends React.PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
this.handleChange = this.handleChange.bind(this);
this.searchTerm = ''; this.searchTerm = '';
} }
handleChange(event) { handleChange = event => {
this.searchTerm = event.target.value; this.searchTerm = event.target.value;
if (event.keyCode === enterKey) { if (event.keyCode === enterKey) {
this.props.search(event.target.value); this.props.search(event.target.value);
} }
} };
render() { render() {
return ( return (

View file

@ -5,10 +5,6 @@ import _ from 'lodash';
export default class SplitPane extends React.PureComponent { export default class SplitPane extends React.PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
this.handleDragStart = this.handleDragStart.bind(this);
this.handleAutoResize = this.handleAutoResize.bind(this);
this.onDrag = this.onDrag.bind(this);
this.onDragEnd = this.onDragEnd.bind(this);
this.state = {dragging: false}; this.state = {dragging: false};
} }
@ -25,7 +21,7 @@ export default class SplitPane extends React.PureComponent {
this.paneIndex -= Math.ceil(this.paneIndex / 2); this.paneIndex -= Math.ceil(this.paneIndex / 2);
} }
handleAutoResize(ev) { handleAutoResize = ev => {
ev.preventDefault(); ev.preventDefault();
this.setupPanes(ev); this.setupPanes(ev);
@ -39,9 +35,9 @@ export default class SplitPane extends React.PureComponent {
sizes_[this.paneIndex + 1] = availableWidth / 2; sizes_[this.paneIndex + 1] = availableWidth / 2;
this.props.onResize(sizes_); this.props.onResize(sizes_);
} };
handleDragStart(ev) { handleDragStart = ev => {
ev.preventDefault(); ev.preventDefault();
this.setState({dragging: true}); this.setState({dragging: true});
window.addEventListener('mousemove', this.onDrag); window.addEventListener('mousemove', this.onDrag);
@ -62,7 +58,7 @@ export default class SplitPane extends React.PureComponent {
this.dragPanePosition = this.dragTarget.getBoundingClientRect()[this.d2]; this.dragPanePosition = this.dragTarget.getBoundingClientRect()[this.d2];
this.panesSize = ev.target.parentNode.getBoundingClientRect()[this.d1]; this.panesSize = ev.target.parentNode.getBoundingClientRect()[this.d1];
this.setupPanes(ev); this.setupPanes(ev);
} };
getSizes() { getSizes() {
const {sizes} = this.props; const {sizes} = this.props;
@ -79,7 +75,7 @@ export default class SplitPane extends React.PureComponent {
return sizes_; return sizes_;
} }
onDrag(ev) { onDrag = ev => {
const sizes_ = this.getSizes(); const sizes_ = this.getSizes();
const i = this.paneIndex; const i = this.paneIndex;
@ -93,15 +89,15 @@ export default class SplitPane extends React.PureComponent {
sizes_[i + 1] += d; sizes_[i + 1] += d;
} }
this.props.onResize(sizes_); this.props.onResize(sizes_);
} };
onDragEnd() { onDragEnd = () => {
if (this.state.dragging) { if (this.state.dragging) {
window.removeEventListener('mousemove', this.onDrag); window.removeEventListener('mousemove', this.onDrag);
window.removeEventListener('mouseup', this.onDragEnd); window.removeEventListener('mouseup', this.onDragEnd);
this.setState({dragging: false}); this.setState({dragging: false});
} }
} };
render() { render() {
const children = this.props.children; const children = this.props.children;

View file

@ -4,43 +4,38 @@ export default class Tab extends React.PureComponent {
constructor() { constructor() {
super(); super();
this.handleHover = this.handleHover.bind(this);
this.handleBlur = this.handleBlur.bind(this);
this.handleClick = this.handleClick.bind(this);
this.handleMouseUp = this.handleMouseUp.bind(this);
this.state = { this.state = {
hovered: false hovered: false
}; };
} }
handleHover() { handleHover = () => {
this.setState({ this.setState({
hovered: true hovered: true
}); });
} };
handleBlur() { handleBlur = () => {
this.setState({ this.setState({
hovered: false hovered: false
}); });
} };
handleClick(event) { handleClick = event => {
const isLeftClick = event.nativeEvent.which === 1; const isLeftClick = event.nativeEvent.which === 1;
if (isLeftClick && !this.props.isActive) { if (isLeftClick && !this.props.isActive) {
this.props.onSelect(); this.props.onSelect();
} }
} };
handleMouseUp(event) { handleMouseUp = event => {
const isMiddleClick = event.nativeEvent.which === 2; const isMiddleClick = event.nativeEvent.which === 2;
if (isMiddleClick) { if (isMiddleClick) {
this.props.onClose(); this.props.onClose();
} }
} };
render() { render() {
const {isActive, isFirst, isLast, borderColor, hasActivity} = this.props; const {isActive, isFirst, isLast, borderColor, hasActivity} = this.props;

View file

@ -13,7 +13,6 @@ class TermGroup_ extends React.PureComponent {
super(props, context); super(props, context);
this.bound = new WeakMap(); this.bound = new WeakMap();
this.termRefs = {}; this.termRefs = {};
this.onTermRef = this.onTermRef.bind(this);
} }
bind(fn, thisObj, uid) { bind(fn, thisObj, uid) {
@ -46,10 +45,10 @@ class TermGroup_ extends React.PureComponent {
); );
} }
onTermRef(uid, term) { onTermRef = (uid, term) => {
this.term = term; this.term = term;
this.props.ref_(uid, term); this.props.ref_(uid, term);
} };
renderTerm(uid) { renderTerm(uid) {
const session = this.props.sessions[uid]; const session = this.props.sessions[uid];

View file

@ -85,13 +85,6 @@ export default class Term extends React.PureComponent {
this.termRef = null; this.termRef = null;
this.termWrapperRef = null; this.termWrapperRef = null;
this.termRect = null; this.termRect = null;
this.onWindowPaste = this.onWindowPaste.bind(this);
this.onTermWrapperRef = this.onTermWrapperRef.bind(this);
this.onMouseUp = this.onMouseUp.bind(this);
this.search = this.search.bind(this);
this.searchNext = this.searchNext.bind(this);
this.searchPrevious = this.searchPrevious.bind(this);
this.closeSearchBox = this.closeSearchBox.bind(this);
this.termOptions = {}; this.termOptions = {};
this.disposableListeners = []; this.disposableListeners = [];
this.termDefaultBellSound = null; this.termDefaultBellSound = null;
@ -230,7 +223,7 @@ export default class Term extends React.PureComponent {
// intercepting paste event for any necessary processing of // intercepting paste event for any necessary processing of
// clipboard data, if result is falsy, paste event continues // clipboard data, if result is falsy, paste event continues
onWindowPaste(e) { onWindowPaste = e => {
if (!this.props.isTermActive) return; if (!this.props.isTermActive) return;
const processed = processClipboard(); const processed = processClipboard();
@ -239,9 +232,9 @@ export default class Term extends React.PureComponent {
e.stopPropagation(); e.stopPropagation();
this.term._core.handler(processed); this.term._core.handler(processed);
} }
} };
onMouseUp(e) { onMouseUp = e => {
if (this.props.quickEdit && e.button === 2) { if (this.props.quickEdit && e.button === 2) {
if (this.term.hasSelection()) { if (this.term.hasSelection()) {
clipboard.writeText(this.term.getSelection()); clipboard.writeText(this.term.getSelection());
@ -252,7 +245,7 @@ export default class Term extends React.PureComponent {
} else if (this.props.copyOnSelect && this.term.hasSelection()) { } else if (this.props.copyOnSelect && this.term.hasSelection()) {
clipboard.writeText(this.term.getSelection()); clipboard.writeText(this.term.getSelection());
} }
} };
write(data) { write(data) {
this.term.write(data); this.term.write(data);
@ -270,21 +263,21 @@ export default class Term extends React.PureComponent {
this.term.reset(); this.term.reset();
} }
search(searchTerm) { search = searchTerm => {
this.searchAddon.findNext(searchTerm); this.searchAddon.findNext(searchTerm);
} };
searchNext(searchTerm) { searchNext = searchTerm => {
this.searchAddon.findNext(searchTerm); this.searchAddon.findNext(searchTerm);
} };
searchPrevious(searchTerm) { searchPrevious = searchTerm => {
this.searchAddon.findPrevious(searchTerm); this.searchAddon.findPrevious(searchTerm);
} };
closeSearchBox() { closeSearchBox = () => {
this.props.toggleSearch(); this.props.toggleSearch();
} };
resize(cols, rows) { resize(cols, rows) {
this.term.resize(cols, rows); this.term.resize(cols, rows);
@ -423,7 +416,7 @@ export default class Term extends React.PureComponent {
} }
} }
onTermWrapperRef(component) { onTermWrapperRef = component => {
this.termWrapperRef = component; this.termWrapperRef = component;
if (component) { if (component) {
@ -437,7 +430,7 @@ export default class Term extends React.PureComponent {
} else { } else {
this.resizeObserver.disconnect(); this.resizeObserver.disconnect();
} }
} };
componentWillUnmount() { componentWillUnmount() {
terms[this.props.uid] = null; terms[this.props.uid] = null;

View file

@ -14,7 +14,6 @@ export default class Terms extends React.Component {
super(props, context); super(props, context);
this.terms = {}; this.terms = {};
this.bound = new WeakMap(); this.bound = new WeakMap();
this.onRef = this.onRef.bind(this);
this.registerCommands = registerCommandHandlers; this.registerCommands = registerCommandHandlers;
props.ref_(this); props.ref_(this);
} }
@ -39,11 +38,11 @@ export default class Terms extends React.Component {
return false; return false;
} }
onRef(uid, term) { onRef = (uid, term) => {
if (term) { if (term) {
this.terms[uid] = term; this.terms[uid] = term;
} }
} };
getTermByUid(uid) { getTermByUid(uid) {
return this.terms[uid]; return this.terms[uid];

View file

@ -21,10 +21,6 @@ class Hyper extends React.PureComponent<any, any> {
terms: any; terms: any;
constructor(props: any) { constructor(props: any) {
super(props); super(props);
this.handleFocusActive = this.handleFocusActive.bind(this);
this.handleSelectAll = this.handleSelectAll.bind(this);
this.onTermsRef = this.onTermsRef.bind(this);
this.state = { this.state = {
lastConfigUpdate: 0 lastConfigUpdate: 0
}; };
@ -43,19 +39,19 @@ class Hyper extends React.PureComponent<any, any> {
} }
} }
handleFocusActive(uid: string) { handleFocusActive = (uid: string) => {
const term = this.terms.getTermByUid(uid); const term = this.terms.getTermByUid(uid);
if (term) { if (term) {
term.focus(); term.focus();
} }
} };
handleSelectAll() { handleSelectAll = () => {
const term = this.terms.getActiveTerm(); const term = this.terms.getActiveTerm();
if (term) { if (term) {
term.selectAll(); term.selectAll();
} }
} };
attachKeyListeners() { attachKeyListeners() {
if (!this.mousetrap) { if (!this.mousetrap) {
@ -89,10 +85,10 @@ class Hyper extends React.PureComponent<any, any> {
window.rpc.on('term selectAll', this.handleSelectAll); window.rpc.on('term selectAll', this.handleSelectAll);
} }
onTermsRef(terms: any) { onTermsRef = (terms: any) => {
this.terms = terms; this.terms = terms;
window.focusActiveTerm = this.handleFocusActive; window.focusActiveTerm = this.handleFocusActive;
} };
componentDidUpdate(prev: any) { componentDidUpdate(prev: any) {
if (prev.activeSession !== this.props.activeSession) { if (prev.activeSession !== this.props.activeSession) {

View file

@ -55,9 +55,8 @@ function exposeDecorated(Component_: any) {
return class DecoratedComponent extends React.Component<any, any> { return class DecoratedComponent extends React.Component<any, any> {
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
this.onRef = this.onRef.bind(this);
} }
onRef(decorated_: any) { onRef = (decorated_: any) => {
if (this.props.onDecorated) { if (this.props.onDecorated) {
try { try {
this.props.onDecorated(decorated_); this.props.onDecorated(decorated_);
@ -65,7 +64,7 @@ function exposeDecorated(Component_: any) {
notify('Plugin error', `Error occurred. Check Developer Tools for details`, {error: e}); notify('Plugin error', `Error occurred. Check Developer Tools for details`, {error: e});
} }
} }
} };
render() { render() {
return React.createElement(Component_, Object.assign({}, this.props, {ref: this.onRef})); return React.createElement(Component_, Object.assign({}, this.props, {ref: this.onRef}));
} }

View file

@ -8,7 +8,6 @@ export default class Client {
constructor() { constructor() {
this.emitter = new EventEmitter(); this.emitter = new EventEmitter();
this.ipc = electron.ipcRenderer; this.ipc = electron.ipcRenderer;
this.ipcListener = this.ipcListener.bind(this);
if (window.__rpcId) { if (window.__rpcId) {
setTimeout(() => { setTimeout(() => {
this.id = window.__rpcId; this.id = window.__rpcId;
@ -28,9 +27,9 @@ export default class Client {
} }
} }
ipcListener(event: any, {ch, data}: {ch: string; data: any}) { ipcListener = (event: any, {ch, data}: {ch: string; data: any}) => {
this.emitter.emit(ch, data); this.emitter.emit(ch, data);
} };
on(ev: string, fn: (...args: any[]) => void) { on(ev: string, fn: (...args: any[]) => void) {
this.emitter.on(ev, fn); this.emitter.on(ev, fn);