remove event emitter and use event and emitter instead (#5361)

This commit is contained in:
Anthony Dresser
2019-05-06 00:27:55 -07:00
committed by GitHub
parent 08ed9d285e
commit b9d985b663
13 changed files with 55 additions and 396 deletions

View File

@@ -5,7 +5,7 @@
import * as GridContentEvents from 'sql/workbench/parts/grid/common/gridContentEvents';
import * as LocalizedConstants from 'sql/workbench/parts/query/common/localizedConstants';
import QueryRunner, { EventType as QREvents } from 'sql/platform/query/common/queryRunner';
import QueryRunner from 'sql/platform/query/common/queryRunner';
import { DataService } from 'sql/workbench/parts/grid/services/dataService';
import { IQueryModelService, IQueryEvent } from 'sql/platform/query/common/queryModel';
import { QueryInput } from 'sql/workbench/parts/query/common/queryInput';
@@ -277,10 +277,10 @@ export class QueryModelService implements IQueryModelService {
private initQueryRunner(uri: string): QueryInfo {
let queryRunner = this._instantiationService.createInstance(QueryRunner, uri);
let info = new QueryInfo();
queryRunner.addListener(QREvents.RESULT_SET, e => {
queryRunner.onResultSet(e => {
this._fireQueryEvent(uri, 'resultSet', e);
});
queryRunner.addListener(QREvents.BATCH_START, b => {
queryRunner.onBatchStart(b => {
let link = undefined;
let messageText = LocalizedConstants.runQueryBatchStartMessage;
if (b.selection) {
@@ -304,10 +304,10 @@ export class QueryModelService implements IQueryModelService {
this._fireQueryEvent(uri, 'message', message);
info.selection.push(this._validateSelection(b.selection));
});
queryRunner.addListener(QREvents.MESSAGE, m => {
queryRunner.onMessage(m => {
this._fireQueryEvent(uri, 'message', m);
});
queryRunner.addListener(QREvents.COMPLETE, totalMilliseconds => {
queryRunner.onQueryEnd(totalMilliseconds => {
this._onRunQueryComplete.fire(uri);
// fire extensibility API event
@@ -320,7 +320,7 @@ export class QueryModelService implements IQueryModelService {
// fire UI event
this._fireQueryEvent(uri, 'complete', totalMilliseconds);
});
queryRunner.addListener(QREvents.START, () => {
queryRunner.onQueryStart(() => {
this._onRunQueryStart.fire(uri);
// fire extensibility API event
@@ -333,7 +333,7 @@ export class QueryModelService implements IQueryModelService {
this._fireQueryEvent(uri, 'start');
});
queryRunner.addListener(QREvents.QUERY_PLAN_AVAILABLE, (planInfo) => {
queryRunner.onQueryPlanAvailable(planInfo => {
// fire extensibility API event
let event: IQueryEvent = {
type: 'executionPlan',
@@ -416,13 +416,13 @@ export class QueryModelService implements IQueryModelService {
// and map it to the results uri
queryRunner = this._instantiationService.createInstance(QueryRunner, ownerUri);
const resultSetEventType = 'resultSet';
queryRunner.addListener(QREvents.RESULT_SET, resultSet => {
queryRunner.onResultSet(resultSet => {
this._fireQueryEvent(ownerUri, resultSetEventType, resultSet);
});
queryRunner.onResultSetUpdate(resultSetSummary => {
this._fireQueryEvent(ownerUri, resultSetEventType, resultSetSummary);
});
queryRunner.addListener(QREvents.BATCH_START, batch => {
queryRunner.onBatchStart(batch => {
let link = undefined;
let messageText = LocalizedConstants.runQueryBatchStartMessage;
if (batch.selection) {
@@ -445,10 +445,10 @@ export class QueryModelService implements IQueryModelService {
};
this._fireQueryEvent(ownerUri, 'message', message);
});
queryRunner.addListener(QREvents.MESSAGE, message => {
queryRunner.onMessage(message => {
this._fireQueryEvent(ownerUri, 'message', message);
});
queryRunner.addListener(QREvents.COMPLETE, totalMilliseconds => {
queryRunner.onQueryEnd(totalMilliseconds => {
this._onRunQueryComplete.fire(ownerUri);
// fire extensibility API event
let event: IQueryEvent = {
@@ -460,7 +460,7 @@ export class QueryModelService implements IQueryModelService {
// fire UI event
this._fireQueryEvent(ownerUri, 'complete', totalMilliseconds);
});
queryRunner.addListener(QREvents.START, () => {
queryRunner.onQueryStart(() => {
this._onRunQueryStart.fire(ownerUri);
// fire extensibility API event
let event: IQueryEvent = {
@@ -472,7 +472,7 @@ export class QueryModelService implements IQueryModelService {
// fire UI event
this._fireQueryEvent(ownerUri, 'start');
});
queryRunner.addListener(QREvents.EDIT_SESSION_READY, e => {
queryRunner.onEditSessionReady(e => {
this._onEditSessionReady.fire(e);
this._fireQueryEvent(e.ownerUri, 'editSessionReady');
});

View File

@@ -11,19 +11,18 @@ import { IQueryManagementService } from 'sql/platform/query/common/queryManageme
import * as Utils from 'sql/platform/connection/common/utils';
import { SaveFormat } from 'sql/workbench/parts/grid/common/interfaces';
import { Deferred } from 'sql/base/common/promise';
import { IQueryPlanInfo } from 'sql/platform/query/common/queryModel';
import { ResultSerializer } from 'sql/platform/node/resultSerializer';
import Severity from 'vs/base/common/severity';
import * as nls from 'vs/nls';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import * as types from 'vs/base/common/types';
import { EventEmitter } from 'sql/base/common/eventEmitter';
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import { Disposable } from 'vs/base/common/lifecycle';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { Emitter, Event } from 'vs/base/common/event';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ResultSerializer } from 'sql/platform/node/resultSerializer';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IQueryPlanInfo } from 'sql/platform/query/common/queryModel';
import { ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
import { URI } from 'vs/base/common/uri';
@@ -33,28 +32,6 @@ export interface IEditSessionReadyEvent {
message: string;
}
export const enum EventType {
START = 'start',
COMPLETE = 'complete',
MESSAGE = 'message',
BATCH_START = 'batchStart',
BATCH_COMPLETE = 'batchComplete',
RESULT_SET = 'resultSet',
EDIT_SESSION_READY = 'editSessionReady',
QUERY_PLAN_AVAILABLE = 'queryPlanAvailable'
}
export interface IEventType {
start: void;
complete: string;
message: azdata.IResultMessage;
batchStart: azdata.BatchSummary;
batchComplete: azdata.BatchSummary;
resultSet: azdata.ResultSetSummary;
editSessionReady: IEditSessionReadyEvent;
queryPlanAvailable: IQueryPlanInfo;
}
export interface IGridMessage extends azdata.IResultMessage {
selection: azdata.ISelectionData;
}
@@ -71,7 +48,6 @@ export default class QueryRunner extends Disposable {
private _hasCompleted: boolean = false;
private _batchSets: azdata.BatchSummary[] = [];
private _messages: azdata.IResultMessage[] = [];
private _eventEmitter = new EventEmitter();
private registered = false;
private _isQueryPlan: boolean;
@@ -80,7 +56,7 @@ export default class QueryRunner extends Disposable {
public get planXml(): Thenable<string> { return this._planXml.promise; }
private _onMessage = this._register(new Emitter<azdata.IResultMessage>());
public readonly onMessage = this._onMessage.event;
public get onMessage(): Event<azdata.IResultMessage> { return this._onMessage.event; } // this is the only way typemoq can moq this... needs investigation @todo anthonydresser 5/2/2019
private _onResultSet = this._register(new Emitter<azdata.ResultSetSummary>());
public readonly onResultSet = this._onResultSet.event;
@@ -92,7 +68,7 @@ export default class QueryRunner extends Disposable {
public readonly onQueryStart: Event<void> = this._onQueryStart.event;
private _onQueryEnd = this._register(new Emitter<string>());
public readonly onQueryEnd: Event<string> = this._onQueryEnd.event;
public get onQueryEnd(): Event<string> { return this._onQueryEnd.event; }
private _onBatchStart = this._register(new Emitter<azdata.BatchSummary>());
public readonly onBatchStart: Event<azdata.BatchSummary> = this._onBatchStart.event;
@@ -100,6 +76,12 @@ export default class QueryRunner extends Disposable {
private _onBatchEnd = this._register(new Emitter<azdata.BatchSummary>());
public readonly onBatchEnd: Event<azdata.BatchSummary> = this._onBatchEnd.event;
private _onEditSessionReady = this._register(new Emitter<IEditSessionReadyEvent>());
public readonly onEditSessionReady = this._onEditSessionReady.event;
private _onQueryPlanAvailable = this._register(new Emitter<IQueryPlanInfo>());
public readonly onQueryPlanAvailable = this._onQueryPlanAvailable.event;
private _queryStartTime: Date;
public get queryStartTime(): Date {
return this._queryStartTime;
@@ -146,10 +128,6 @@ export default class QueryRunner extends Disposable {
// PUBLIC METHODS ======================================================
public addListener<K extends keyof IEventType>(event: K, f: (e: IEventType[K]) => void): IDisposable {
return this._eventEmitter.addListener(event, f);
}
/**
* Cancels the running query, if there is one
*/
@@ -229,7 +207,6 @@ export default class QueryRunner extends Disposable {
// this isn't exact, but its the best we can do
this._queryStartTime = new Date();
// The query has started, so lets fire up the result pane
this._eventEmitter.emit(EventType.START);
if (!this.registered) {
this.registered = true;
this._queryManagementService.registerRunner(this, this.uri);
@@ -270,8 +247,6 @@ export default class QueryRunner extends Disposable {
});
let timeStamp = Utils.parseNumAsTimeString(this._totalElapsedMilliseconds);
this._eventEmitter.emit(EventType.COMPLETE, timeStamp);
// We're done with this query so shut down any waiting mechanisms
let message = {
@@ -311,7 +286,6 @@ export default class QueryRunner extends Disposable {
isError: false
};
this._messages.push(message);
this._eventEmitter.emit(EventType.BATCH_START, batch);
this._onMessage.fire(message);
this._onBatchStart.fire(batch);
}
@@ -331,7 +305,6 @@ export default class QueryRunner extends Disposable {
this.sendBatchTimeMessage(batch.id, Utils.parseNumAsTimeString(executionTime));
}
this._eventEmitter.emit(EventType.BATCH_COMPLETE, batch);
this._onBatchEnd.fire(batch);
}
@@ -376,7 +349,6 @@ export default class QueryRunner extends Disposable {
if (batchSet && !batchSet.resultSetSummaries[resultSet.id]) {
// Store the result set in the batch and emit that a result set has completed
batchSet.resultSetSummaries[resultSet.id] = resultSet;
this._eventEmitter.emit(EventType.RESULT_SET, resultSet);
this._onResultSet.fire(resultSet);
}
}
@@ -398,7 +370,7 @@ export default class QueryRunner extends Disposable {
this._planXml.resolve(e.resultSubset.rows[0][0].displayValue);
// fire query plan available event if execution is completed
if (result.resultSetSummary.complete) {
this._eventEmitter.emit(EventType.QUERY_PLAN_AVAILABLE, {
this._onQueryPlanAvailable.fire({
providerId: 'MSSQL',
fileUri: result.ownerUri,
planXml: planXmlString
@@ -425,7 +397,6 @@ export default class QueryRunner extends Disposable {
this._messages.push(message);
// Send the message to the results pane
this._eventEmitter.emit(EventType.MESSAGE, message);
this._onMessage.fire(message);
}
@@ -461,7 +432,7 @@ export default class QueryRunner extends Disposable {
return this._queryManagementService.initializeEdit(ownerUri, schemaName, objectName, objectType, rowLimit, queryString).then(result => {
// The query has started, so lets fire up the result pane
this._eventEmitter.emit(EventType.START);
this._onQueryStart.fire();
this._queryManagementService.registerRunner(this, ownerUri);
}, error => {
// Attempting to launch the query failed, show the error message
@@ -511,7 +482,7 @@ export default class QueryRunner extends Disposable {
}
public handleEditSessionReady(ownerUri: string, success: boolean, message: string): void {
this._eventEmitter.emit(EventType.EDIT_SESSION_READY, { ownerUri, success, message });
this._onEditSessionReady.fire({ ownerUri, success, message });
}
public updateCell(ownerUri: string, rowId: number, columnId: number, newValue: string): Thenable<azdata.EditUpdateCellResult> {