Move survey ready logic into Surveyor

This commit is contained in:
Matt Bierner
2018-11-15 17:54:46 -08:00
parent 106cbdec2c
commit a0f0ee42e9
2 changed files with 11 additions and 5 deletions

View File

@@ -90,8 +90,7 @@ function createLazyClientHost(
context.subscriptions.push(clientHost);
const surveyor = new Surveyor(context.globalState);
context.subscriptions.push(clientHost.serviceClient.onSurveyReady(e => surveyor.surveyReady(e.surveyId)));
context.subscriptions.push(new Surveyor(context.globalState, clientHost.serviceClient));
clientHost.serviceClient.onReady(() => {
context.subscriptions.push(

View File

@@ -5,6 +5,8 @@
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import TypeScriptServiceClient from '../typescriptServiceClient';
import { Disposable } from './dispose';
const localize = nls.loadMessageBundle();
@@ -121,18 +123,23 @@ class Survey {
}
}
export class Surveyor {
export class Surveyor extends Disposable {
private readonly surveys: Map<string, Survey>;
public constructor(
memento: vscode.Memento
memento: vscode.Memento,
serviceClient: TypeScriptServiceClient,
) {
super();
this.surveys = new Map<string, Survey>(allSurveys.map(data =>
[data.id, new Survey(data, memento)] as [string, Survey]));
this._register(serviceClient.onSurveyReady(e => this.surveyReady(e.surveyId)));
}
public surveyReady(surveyId: string): void {
private surveyReady(surveyId: string): void {
const survey = this.tryGetActiveSurvey(surveyId);
if (survey && survey.trigger()) {
survey.willShow();