Using private fields for more in extHostWebviews

This commit is contained in:
Matt Bierner 2020-02-28 14:08:38 -08:00
parent d4dc9e09a2
commit 4b046579d8

View file

@ -104,19 +104,20 @@ export class ExtHostWebviewEditor extends Disposable implements vscode.WebviewPa
private _title: string;
private _iconPath?: IconPath;
private readonly _options: vscode.WebviewPanelOptions;
private readonly _webview: ExtHostWebview;
private _viewColumn: vscode.ViewColumn | undefined;
private _visible: boolean = true;
private _active: boolean = true;
readonly #options: vscode.WebviewPanelOptions;
readonly #webview: ExtHostWebview;
_isDisposed: boolean = false;
#viewColumn: vscode.ViewColumn | undefined = undefined;
#visible: boolean = true;
#active: boolean = true;
readonly _onDisposeEmitter = this._register(new Emitter<void>());
public readonly onDidDispose: Event<void> = this._onDisposeEmitter.event;
#isDisposed: boolean = false;
readonly _onDidChangeViewStateEmitter = this._register(new Emitter<vscode.WebviewPanelOnDidChangeViewStateEvent>());
public readonly onDidChangeViewState: Event<vscode.WebviewPanelOnDidChangeViewStateEvent> = this._onDidChangeViewStateEmitter.event;
readonly #onDidDispose = this._register(new Emitter<void>());
public readonly onDidDispose = this.#onDidDispose.event;
readonly #onDidChangeViewState = this._register(new Emitter<vscode.WebviewPanelOnDidChangeViewStateEvent>());
public readonly onDidChangeViewState = this.#onDidChangeViewState.event;
constructor(
handle: WebviewPanelHandle,
@ -131,27 +132,28 @@ export class ExtHostWebviewEditor extends Disposable implements vscode.WebviewPa
this._handle = handle;
this._proxy = proxy;
this._viewType = viewType;
this._options = editorOptions;
this._viewColumn = viewColumn;
this.#options = editorOptions;
this.#viewColumn = viewColumn;
this._title = title;
this._webview = webview;
this.#webview = webview;
}
public dispose() {
if (this._isDisposed) {
if (this.#isDisposed) {
return;
}
this._isDisposed = true;
this._onDisposeEmitter.fire();
this.#isDisposed = true;
this.#onDidDispose.fire();
this._proxy.$disposeWebview(this._handle);
this._webview.dispose();
this.#webview.dispose();
super.dispose();
}
get webview() {
this.assertNotDisposed();
return this._webview;
return this.#webview;
}
get viewType(): string {
@ -187,42 +189,40 @@ export class ExtHostWebviewEditor extends Disposable implements vscode.WebviewPa
}
get options() {
return this._options;
return this.#options;
}
get viewColumn(): vscode.ViewColumn | undefined {
this.assertNotDisposed();
if (typeof this._viewColumn === 'number' && this._viewColumn < 0) {
if (typeof this.#viewColumn === 'number' && this.#viewColumn < 0) {
// We are using a symbolic view column
// Return undefined instead to indicate that the real view column is currently unknown but will be resolved.
return undefined;
}
return this._viewColumn;
}
_setViewColumn(value: vscode.ViewColumn) {
this.assertNotDisposed();
this._viewColumn = value;
return this.#viewColumn;
}
public get active(): boolean {
this.assertNotDisposed();
return this._active;
}
_setActive(value: boolean) {
this.assertNotDisposed();
this._active = value;
return this.#active;
}
public get visible(): boolean {
this.assertNotDisposed();
return this._visible;
return this.#visible;
}
_setVisible(value: boolean) {
this.assertNotDisposed();
this._visible = value;
_updateViewState(newState: { active: boolean; visible: boolean; viewColumn: vscode.ViewColumn; }) {
if (this.#isDisposed) {
return;
}
if (this.active !== newState.active || this.visible !== newState.visible || this.viewColumn !== newState.viewColumn) {
this.#active = newState.active;
this.#visible = newState.visible;
this.#viewColumn = newState.viewColumn;
this.#onDidChangeViewState.fire({ webviewPanel: this });
}
}
public postMessage(message: any): Promise<boolean> {
@ -239,7 +239,7 @@ export class ExtHostWebviewEditor extends Disposable implements vscode.WebviewPa
}
private assertNotDisposed() {
if (this._isDisposed) {
if (this.#isDisposed) {
throw new Error('Webview is disposed');
}
}
@ -585,18 +585,16 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
for (const handle of handles) {
const panel = this.getWebviewPanel(handle);
if (!panel || panel._isDisposed) {
if (!panel) {
continue;
}
const newState = newStates[handle];
const viewColumn = typeConverters.ViewColumn.to(newState.position);
if (panel.active !== newState.active || panel.visible !== newState.visible || panel.viewColumn !== viewColumn) {
panel._setActive(newState.active);
panel._setVisible(newState.visible);
panel._setViewColumn(viewColumn);
panel._onDidChangeViewStateEmitter.fire({ webviewPanel: panel });
}
panel._updateViewState({
active: newState.active,
visible: newState.visible,
viewColumn: typeConverters.ViewColumn.to(newState.position),
});
}
}