microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/extension/networkInspector/views/inspectorViewFactory.ts
34lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. |
| 3 | |
| 4 | import { OutputChannelLogger } from "../../log/OutputChannelLogger"; |
| 5 | import { NETWORK_INSPECTOR_LOG_CHANNEL_NAME } from "../networkInspectorServer"; |
| 6 | import { InspectorConsoleView } from "./inspectorConsoleView"; |
| 7 | import { InspectorViewType, InspectorView } from "./inspectorView"; |
| 8 | |
| 9 | export class InspectorViewFactory { |
| 10 | private static cachedInspectorViews = new Map<InspectorViewType, InspectorView>(); |
| 11 | |
| 12 | public static getInspectorView(inspectorViewType: InspectorViewType): InspectorView { |
| 13 | if (!InspectorViewFactory.cachedInspectorViews.has(inspectorViewType)) { |
| 14 | if (inspectorViewType === InspectorViewType.console) { |
| 15 | InspectorViewFactory.cachedInspectorViews.set( |
| 16 | InspectorViewType.console, |
| 17 | new InspectorConsoleView( |
| 18 | OutputChannelLogger.getChannel(NETWORK_INSPECTOR_LOG_CHANNEL_NAME), |
| 19 | ), |
| 20 | ); |
| 21 | } else { |
| 22 | throw new Error(`Unsupported inspector view type: ${inspectorViewType}`); |
| 23 | } |
| 24 | } |
| 25 | return InspectorViewFactory.cachedInspectorViews.get(inspectorViewType) as InspectorView; |
| 26 | } |
| 27 | |
| 28 | public static clearCache(): void { |
| 29 | InspectorViewFactory.cachedInspectorViews.forEach(inspectorView => { |
| 30 | inspectorView.dispose(); |
| 31 | }); |
| 32 | InspectorViewFactory.cachedInspectorViews.clear(); |
| 33 | } |
| 34 | } |
| 35 | |