From 579d0877f0fbffc68c818a9a078df0c0e469d9cc Mon Sep 17 00:00:00 2001 From: Labhansh Agrawal Date: Sun, 15 Mar 2020 04:11:30 +0530 Subject: [PATCH] Remove usage of legacy and soon deprecated lifecycle methods --- lib/components/notification.tsx | 14 ++++---- lib/components/term.js | 59 --------------------------------- lib/containers/hyper.tsx | 27 ++++++--------- lib/hyper.d.ts | 4 +++ 4 files changed, 21 insertions(+), 83 deletions(-) diff --git a/lib/components/notification.tsx b/lib/components/notification.tsx index 0240cbdd..03337cfd 100644 --- a/lib/components/notification.tsx +++ b/lib/components/notification.tsx @@ -1,7 +1,7 @@ import React from 'react'; -import {NotificationProps} from '../hyper'; +import {NotificationProps, NotificationState} from '../hyper'; -export default class Notification extends React.PureComponent { +export default class Notification extends React.PureComponent { dismissTimer!: NodeJS.Timeout; constructor(props: NotificationProps) { super(props); @@ -15,15 +15,15 @@ export default class Notification extends React.PureComponent option !== 'theme' && nextTermOptions[option] !== this.termOptions[option]) - .forEach(option => { - try { - this.term.setOption(option, nextTermOptions[option]); - } catch (e) { - if (/The webgl renderer only works with the webgl char atlas/i.test(e.message)) { - // Ignore this because the char atlas will also be changed - } else { - throw e; - } - } - }); - - // Do we need to update theme? - const shouldUpdateTheme = - !this.termOptions.theme || - nextTermOptions.rendererType !== this.termOptions.rendererType || - Object.keys(nextTermOptions.theme).some( - option => nextTermOptions.theme[option] !== this.termOptions.theme[option] - ); - if (shouldUpdateTheme) { - this.term.setOption('theme', nextTermOptions.theme); - } - - this.termOptions = nextTermOptions; - - if ( - this.props.fontSize !== nextProps.fontSize || - this.props.fontFamily !== nextProps.fontFamily || - this.props.lineHeight !== nextProps.lineHeight || - this.props.letterSpacing !== nextProps.letterSpacing - ) { - // resize to fit the container - this.fitResize(); - } - - if (nextProps.rows !== this.props.rows || nextProps.cols !== this.props.cols) { - this.resize(nextProps.cols, nextProps.rows); - } - } - onTermWrapperRef = component => { this.termWrapperRef = component; diff --git a/lib/containers/hyper.tsx b/lib/containers/hyper.tsx index b2e4afd0..57a6d8b6 100644 --- a/lib/containers/hyper.tsx +++ b/lib/containers/hyper.tsx @@ -13,27 +13,26 @@ import {HyperState, HyperProps, HyperDispatch} from '../hyper'; const isMac = /Mac/.test(navigator.userAgent); -class Hyper extends React.PureComponent { +class Hyper extends React.PureComponent { mousetrap!: MousetrapInstance; terms: any; constructor(props: HyperProps) { super(props); - this.state = { - lastConfigUpdate: 0 - }; } - //TODO: Remove usage of legacy and soon deprecated lifecycle methods - UNSAFE_componentWillReceiveProps(next: HyperProps) { - if (this.props.backgroundColor !== next.backgroundColor) { + + componentDidUpdate(prev: HyperProps) { + if (this.props.backgroundColor !== prev.backgroundColor) { // this can be removed when `setBackgroundColor` in electron // starts working again - document.body.style.backgroundColor = next.backgroundColor; + document.body.style.backgroundColor = this.props.backgroundColor; } - const {lastConfigUpdate} = next; - if (lastConfigUpdate && lastConfigUpdate !== this.state.lastConfigUpdate) { - this.setState({lastConfigUpdate}); + const {lastConfigUpdate} = this.props; + if (lastConfigUpdate && lastConfigUpdate !== prev.lastConfigUpdate) { this.attachKeyListeners(); } + if (prev.activeSession !== this.props.activeSession) { + this.handleFocusActive(this.props.activeSession!); + } } handleFocusActive = (uid: string) => { @@ -87,12 +86,6 @@ class Hyper extends React.PureComponent window.focusActiveTerm = this.handleFocusActive; }; - componentDidUpdate(prev: HyperProps) { - if (prev.activeSession !== this.props.activeSession) { - this.handleFocusActive(this.props.activeSession!); - } - } - componentWillUnmount() { document.body.style.backgroundColor = 'inherit'; this.mousetrap && this.mousetrap.reset(); diff --git a/lib/hyper.d.ts b/lib/hyper.d.ts index 6606a859..d5c273f7 100644 --- a/lib/hyper.d.ts +++ b/lib/hyper.d.ts @@ -252,6 +252,10 @@ export type NotificationProps = { userDismissColor?: string; } & extensionProps; +export type NotificationState = { + dismissing: boolean; +}; + export type SplitPaneProps = { borderColor: string; direction: 'horizontal' | 'vertical';