diff --git a/lib/socket/api-request-handler.react.js b/lib/socket/api-request-handler.react.js --- a/lib/socket/api-request-handler.react.js +++ b/lib/socket/api-request-handler.react.js @@ -26,7 +26,7 @@ +connection: ConnectionInfo, }; class APIRequestHandler extends React.PureComponent { - static isConnected(props: Props, request?: APIRequest) { + static isConnected(props: Props, request?: APIRequest): boolean { const { inflightRequests, connection } = props; if (!inflightRequests) { return false; @@ -44,11 +44,11 @@ // will be a great way to rewrite them to be related but still separated. return ( connection.status === 'connected' || - (request && request.endpoint === 'update_activity') + request?.endpoint === 'update_activity' ); } - get registeredResponseFetcher() { + get registeredResponseFetcher(): ?(request: APIRequest) => Promise { return APIRequestHandler.isConnected(this.props) ? this.fetchResponse : null; @@ -70,11 +70,11 @@ } } - render() { + render(): React.Node { return null; } - fetchResponse = async (request: APIRequest): Promise => { + fetchResponse = async (request: APIRequest): Promise => { if (!APIRequestHandler.isConnected(this.props, request)) { throw new SocketOffline('socket_offline'); } diff --git a/lib/socket/calendar-query-handler.react.js b/lib/socket/calendar-query-handler.react.js --- a/lib/socket/calendar-query-handler.react.js +++ b/lib/socket/calendar-query-handler.react.js @@ -82,11 +82,11 @@ } } - render() { + render(): React.Node { return null; } - get isExpired() { + get isExpired(): boolean { const timeUntilExpiration = timeUntilCalendarRangeExpiration( this.props.lastUserInteractionCalendar, ); @@ -97,7 +97,7 @@ ); } - get shouldUpdateCalendarQuery() { + get shouldUpdateCalendarQuery(): boolean { if (this.props.connection.status !== 'connected' || this.props.frozen) { return false; } diff --git a/lib/socket/inflight-requests.js b/lib/socket/inflight-requests.js --- a/lib/socket/inflight-requests.js +++ b/lib/socket/inflight-requests.js @@ -104,11 +104,9 @@ }; } }); - invariant( - inflightRequest, - `${expectedType} is an invalid server response type`, - ); - this.data.push(inflightRequest); + const request = inflightRequest; + invariant(request, `${expectedType} is an invalid server response type`); + this.data.push(request); // We create this object so we can pass it by reference to the timeout // function below. That function will avoid setting this request as late if @@ -124,12 +122,12 @@ if (requestResult.lateResponse) { this.setLateResponse(messageID, false); } - this.clearRequest(inflightRequest); + this.clearRequest(request); // Flow is unable to narrow the return type based on the expectedType return (response: any); } catch (e) { requestResult.concluded = true; - this.clearRequest(inflightRequest); + this.clearRequest(request); if (e instanceof SocketTimeout) { this.rejectAll(new Error('socket closed due to timeout')); this.timeoutCallback(); @@ -144,7 +142,7 @@ messageID: number, expectedType: ServerSocketMessageType, requestResult: { concluded: boolean, lateResponse: boolean }, - ) { + ): Promise { await sleep(clientRequestVisualTimeout); if (requestResult.concluded) { // We're just doing this to bail out. If requestResult.concluded we can diff --git a/lib/socket/report-handler.react.js b/lib/socket/report-handler.react.js --- a/lib/socket/report-handler.react.js +++ b/lib/socket/report-handler.react.js @@ -52,7 +52,7 @@ } } - render() { + render(): React.Node { return null; } @@ -66,9 +66,11 @@ ); } - async sendReports(reports: $ReadOnlyArray) { + async sendReports( + reports: $ReadOnlyArray, + ): Promise { await sendReports(reports); - return ({ reports }: ClearDeliveredReportsPayload); + return { reports }; } } diff --git a/lib/socket/request-response-handler.react.js b/lib/socket/request-response-handler.react.js --- a/lib/socket/request-response-handler.react.js +++ b/lib/socket/request-response-handler.react.js @@ -48,7 +48,7 @@ this.props.removeListener(this.onMessage); } - render() { + render(): React.Node { return null; }