import { emitter } from '../util/emitter'; import { VscodeListener } from '../listeners/vscode'; import { VSCodeInterface, EditorType } from '../models/ext_models'; export class EditorFlow { private static instance: EditorFlow; public static selectedType: EditorType = EditorType.VSCODE; private vscodeListener: VscodeListener | undefined; static getInstance(type: EditorType, iface: VSCodeInterface): EditorFlow { if (!EditorFlow.instance) { EditorFlow.instance = new EditorFlow(type, iface); } return EditorFlow.instance; } private constructor(type: EditorType, iface: VSCodeInterface) { EditorFlow.selectedType = type; if (EditorFlow.selectedType === EditorType.VSCODE) { this.vscodeListener = new VscodeListener(iface); } else { throw new Error(`${EditorFlow.selectedType} is currently not supported`); } } public getEmitter() { return emitter; } public getSubscriptions() { if (EditorFlow.selectedType === EditorType.VSCODE && this.vscodeListener) { return this.vscodeListener.getSubscriptions(); } return []; } public dispose() { if (EditorFlow.selectedType === EditorType.VSCODE && this.vscodeListener) { this.vscodeListener.dispose(); } } }