From 39c64727fe87612257351a1fa5c42ed09dfe6474 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 27 Oct 2017 16:24:30 -0700 Subject: [PATCH] Convert dispatchEvent to switch --- .../typescript/src/typescriptServiceClient.ts | 75 ++++++++++++------- 1 file changed, 46 insertions(+), 29 deletions(-) diff --git a/extensions/typescript/src/typescriptServiceClient.ts b/extensions/typescript/src/typescriptServiceClient.ts index 674f61e4056..08bca5d59ac 100644 --- a/extensions/typescript/src/typescriptServiceClient.ts +++ b/extensions/typescript/src/typescriptServiceClient.ts @@ -730,35 +730,52 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient } private dispatchEvent(event: Proto.Event) { - if (event.event === 'syntaxDiag') { - this.host.syntaxDiagnosticsReceived(event as Proto.DiagnosticEvent); - } else if (event.event === 'semanticDiag') { - this.host.semanticDiagnosticsReceived(event as Proto.DiagnosticEvent); - } else if (event.event === 'configFileDiag') { - this.host.configFileDiagnosticsReceived(event as Proto.ConfigFileDiagnosticEvent); - } else if (event.event === 'telemetry') { - const telemetryData = (event as Proto.TelemetryEvent).body; - this.dispatchTelemetryEvent(telemetryData); - } else if (event.event === 'projectLanguageServiceState') { - const data = (event as Proto.ProjectLanguageServiceStateEvent).body; - if (data) { - this._onProjectLanguageServiceStateChanged.fire(data); - } - } else if (event.event === 'beginInstallTypes') { - const data = (event as Proto.BeginInstallTypesEvent).body; - if (data) { - this._onDidBeginInstallTypings.fire(data); - } - } else if (event.event === 'endInstallTypes') { - const data = (event as Proto.EndInstallTypesEvent).body; - if (data) { - this._onDidEndInstallTypings.fire(data); - } - } else if (event.event === 'typesInstallerInitializationFailed') { - const data = (event as Proto.TypesInstallerInitializationFailedEvent).body; - if (data) { - this._onTypesInstallerInitializationFailed.fire(data); - } + switch (event.event) { + case 'syntaxDiag': + this.host.syntaxDiagnosticsReceived(event as Proto.DiagnosticEvent); + break; + + case 'semanticDiag': + this.host.semanticDiagnosticsReceived(event as Proto.DiagnosticEvent); + break; + + case 'configFileDiag': + this.host.configFileDiagnosticsReceived(event as Proto.ConfigFileDiagnosticEvent); + break; + + case 'telemetry': + const telemetryData = (event as Proto.TelemetryEvent).body; + this.dispatchTelemetryEvent(telemetryData); + break; + + case 'projectLanguageServiceState': + if (event.body) { + const data = (event as Proto.ProjectLanguageServiceStateEvent).body; + + this._onProjectLanguageServiceStateChanged.fire(data); + } + break; + + case 'beginInstallTypes': + if (event.body) { + const data = (event as Proto.BeginInstallTypesEvent).body; + this._onDidBeginInstallTypings.fire(data); + } + break; + + case 'endInstallTypes': + if (event.body) { + const data = (event as Proto.EndInstallTypesEvent).body; + this._onDidEndInstallTypings.fire(data); + } + break; + + case 'typesInstallerInitializationFailed': + if (event.body) { + const data = (event as Proto.TypesInstallerInitializationFailedEvent).body; + this._onTypesInstallerInitializationFailed.fire(data); + } + break; } } -- GitLab