Merge pull request #2434 from github/robertbrignull/disposable-event-emitter
Mark AppEventEmitter as disposable
This commit is contained in:
@@ -4,7 +4,7 @@ export interface AppEvent<T> {
|
||||
(listener: (event: T) => void): Disposable;
|
||||
}
|
||||
|
||||
export interface AppEventEmitter<T> {
|
||||
export interface AppEventEmitter<T> extends Disposable {
|
||||
event: AppEvent<T>;
|
||||
fire(data: T): void;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,9 @@ export class DbConfigStore extends DisposableObject {
|
||||
this.configErrors = [];
|
||||
this.configWatcher = undefined;
|
||||
this.configValidator = new DbConfigValidator(app.extensionPath);
|
||||
this.onDidChangeConfigEventEmitter = app.createEventEmitter<void>();
|
||||
this.onDidChangeConfigEventEmitter = this.push(
|
||||
app.createEventEmitter<void>(),
|
||||
);
|
||||
this.onDidChangeConfig = this.onDidChangeConfigEventEmitter.event;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { App } from "../common/app";
|
||||
import { AppEvent, AppEventEmitter } from "../common/events";
|
||||
import { ValueResult } from "../common/value-result";
|
||||
import { DisposableObject } from "../pure/disposable-object";
|
||||
import { DbConfigStore } from "./config/db-config-store";
|
||||
import {
|
||||
DbItem,
|
||||
@@ -23,7 +24,7 @@ import {
|
||||
import { createRemoteTree } from "./db-tree-creator";
|
||||
import { DbConfigValidationError } from "./db-validation-errors";
|
||||
|
||||
export class DbManager {
|
||||
export class DbManager extends DisposableObject {
|
||||
public readonly onDbItemsChanged: AppEvent<void>;
|
||||
public static readonly DB_EXPANDED_STATE_KEY = "db_expanded";
|
||||
private readonly onDbItemsChangesEventEmitter: AppEventEmitter<void>;
|
||||
@@ -32,7 +33,11 @@ export class DbManager {
|
||||
private readonly app: App,
|
||||
private readonly dbConfigStore: DbConfigStore,
|
||||
) {
|
||||
this.onDbItemsChangesEventEmitter = app.createEventEmitter<void>();
|
||||
super();
|
||||
|
||||
this.onDbItemsChangesEventEmitter = this.push(
|
||||
app.createEventEmitter<void>(),
|
||||
);
|
||||
this.onDbItemsChanged = this.onDbItemsChangesEventEmitter.event;
|
||||
|
||||
this.dbConfigStore.onDidChangeConfig(() => {
|
||||
|
||||
@@ -17,7 +17,7 @@ export class DbModule extends DisposableObject {
|
||||
super();
|
||||
|
||||
this.dbConfigStore = new DbConfigStore(app);
|
||||
this.dbManager = new DbManager(app, this.dbConfigStore);
|
||||
this.dbManager = this.push(new DbManager(app, this.dbConfigStore));
|
||||
}
|
||||
|
||||
public static async initialize(app: App): Promise<DbModule> {
|
||||
|
||||
@@ -63,4 +63,8 @@ export class MockAppEventEmitter<T> implements AppEventEmitter<T> {
|
||||
public fire(): void {
|
||||
// no-op
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user