mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Add clear
method on DisposableStore
`clear` disposes of all tracked disposables but does not mark the store itself as disposed. If you need a mutatable list of disposables, this allows you to always use `readonly`/`const` disposable stores that can be registered on the base class.
This commit is contained in:
parent
a55cfe1e39
commit
2197cd0931
|
@ -46,8 +46,20 @@ export class DisposableStore implements IDisposable {
|
|||
private _toDispose: IDisposable[] = [];
|
||||
private _isDisposed = false;
|
||||
|
||||
/**
|
||||
* Dispose of all registered disposables and mark this object as disposed.
|
||||
*
|
||||
* Any future disposables added to this object will be disposed of on `push`.
|
||||
*/
|
||||
public dispose(): void {
|
||||
this._isDisposed = true;
|
||||
this.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispose of all registered disposables but do not mark this object as disposed.
|
||||
*/
|
||||
public clear(): void {
|
||||
this._toDispose = dispose(this._toDispose);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ export class ModesHoverController implements IEditorContribution {
|
|||
|
||||
private static readonly ID = 'editor.contrib.hover';
|
||||
|
||||
private _toUnhook = new DisposableStore();
|
||||
private readonly _toUnhook = new DisposableStore();
|
||||
private readonly _didChangeConfigurationHandler: IDisposable;
|
||||
|
||||
private _contentWidget: ModesContentHoverWidget;
|
||||
|
@ -109,8 +109,7 @@ export class ModesHoverController implements IEditorContribution {
|
|||
}
|
||||
|
||||
private _unhookEvents(): void {
|
||||
this._toUnhook.dispose();
|
||||
this._toUnhook = new DisposableStore();
|
||||
this._toUnhook.clear();
|
||||
}
|
||||
|
||||
private _onModelDecorationsChanged(): void {
|
||||
|
@ -226,6 +225,7 @@ export class ModesHoverController implements IEditorContribution {
|
|||
|
||||
public dispose(): void {
|
||||
this._unhookEvents();
|
||||
this._toUnhook.dispose();
|
||||
this._didChangeConfigurationHandler.dispose();
|
||||
|
||||
if (this._glyphWidget) {
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
import * as DOM from 'vs/base/browser/dom';
|
||||
import { Button } from 'vs/base/browser/ui/button/button';
|
||||
import { IAction } from 'vs/base/common/actions';
|
||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IMenu } from 'vs/platform/actions/common/actions';
|
||||
import { attachButtonStyler } from 'vs/platform/theme/common/styler';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
|
||||
export class CommentFormActions {
|
||||
export class CommentFormActions implements IDisposable {
|
||||
private _buttonElements: HTMLElement[] = [];
|
||||
private _toDispose = new DisposableStore();
|
||||
private readonly _toDispose = new DisposableStore();
|
||||
|
||||
constructor(
|
||||
private container: HTMLElement,
|
||||
|
@ -22,8 +22,7 @@ export class CommentFormActions {
|
|||
) { }
|
||||
|
||||
setActions(menu: IMenu) {
|
||||
this._toDispose.dispose();
|
||||
this._toDispose = new DisposableStore();
|
||||
this._toDispose.clear();
|
||||
|
||||
this._buttonElements.forEach(b => DOM.removeNode(b));
|
||||
|
||||
|
@ -44,4 +43,8 @@ export class CommentFormActions {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this._toDispose.dispose();
|
||||
}
|
||||
}
|
|
@ -960,7 +960,7 @@ export class DirtyDiffModel extends Disposable {
|
|||
private diffDelayer: ThrottledDelayer<IChange[] | null> | null;
|
||||
private _originalURIPromise?: Promise<URI | null>;
|
||||
private repositoryDisposables = new Set<IDisposable>();
|
||||
private originalModelDisposables: IDisposable = Disposable.None;
|
||||
private readonly originalModelDisposables = this._register(new DisposableStore());
|
||||
|
||||
private _onDidChange = new Emitter<ISplice<IChange>[]>();
|
||||
readonly onDidChange: Event<ISplice<IChange>[]> = this._onDidChange.event;
|
||||
|
@ -1069,12 +1069,9 @@ export class DirtyDiffModel extends Disposable {
|
|||
|
||||
this._originalModel = ref.object.textEditorModel;
|
||||
|
||||
const originalModelDisposables = new DisposableStore();
|
||||
originalModelDisposables.push(ref);
|
||||
originalModelDisposables.push(ref.object.textEditorModel.onDidChangeContent(() => this.triggerDiff()));
|
||||
|
||||
this.originalModelDisposables.dispose();
|
||||
this.originalModelDisposables = originalModelDisposables;
|
||||
this.originalModelDisposables.clear();
|
||||
this.originalModelDisposables.push(ref);
|
||||
this.originalModelDisposables.push(ref.object.textEditorModel.onDidChangeContent(() => this.triggerDiff()));
|
||||
|
||||
return originalUri;
|
||||
});
|
||||
|
@ -1131,7 +1128,6 @@ export class DirtyDiffModel extends Disposable {
|
|||
}
|
||||
|
||||
dispose(): void {
|
||||
this.originalModelDisposables = dispose(this.originalModelDisposables);
|
||||
super.dispose();
|
||||
|
||||
this._editorModel = null;
|
||||
|
|
|
@ -295,10 +295,10 @@ class SnippetsService implements ISnippetsService {
|
|||
}
|
||||
|
||||
private _initFolderSnippets(source: SnippetSource, folder: URI, bucket: IDisposable[]): Promise<any> {
|
||||
let disposables = new DisposableStore();
|
||||
let addFolderSnippets = (type?: FileChangeType) => {
|
||||
disposables.dispose();
|
||||
disposables = new DisposableStore();
|
||||
const disposables = new DisposableStore();
|
||||
const addFolderSnippets = (type?: FileChangeType) => {
|
||||
disposables.clear();
|
||||
|
||||
if (type === FileChangeType.DELETED) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ export class WebviewEditor extends BaseEditor {
|
|||
private _content?: HTMLElement;
|
||||
private _webviewContent: HTMLElement | undefined;
|
||||
|
||||
private _webviewFocusTrackerDisposables = new DisposableStore();
|
||||
private readonly _webviewFocusTrackerDisposables = new DisposableStore();
|
||||
private _onFocusWindowHandler?: IDisposable;
|
||||
|
||||
private readonly _onDidFocusWebview = this._register(new Emitter<void>());
|
||||
|
@ -304,8 +304,7 @@ export class WebviewEditor extends BaseEditor {
|
|||
}
|
||||
|
||||
private trackFocus() {
|
||||
this._webviewFocusTrackerDisposables.dispose();
|
||||
this._webviewFocusTrackerDisposables = new DisposableStore();
|
||||
this._webviewFocusTrackerDisposables.clear();
|
||||
|
||||
// Track focus in webview content
|
||||
const webviewContentFocusTracker = DOM.trackFocus(this._webviewContent!);
|
||||
|
|
|
@ -125,7 +125,7 @@ suite('Disk File Service', () => {
|
|||
let testProvider: TestDiskFileSystemProvider;
|
||||
let testDir: string;
|
||||
|
||||
let disposables = new DisposableStore();
|
||||
const disposables = new DisposableStore();
|
||||
|
||||
setup(async () => {
|
||||
const logService = new NullLogService();
|
||||
|
@ -149,8 +149,7 @@ suite('Disk File Service', () => {
|
|||
});
|
||||
|
||||
teardown(async () => {
|
||||
disposables.dispose();
|
||||
disposables = new DisposableStore();
|
||||
disposables.clear();
|
||||
|
||||
await rimraf(parentDir, RimRafMode.MOVE);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue