From cf9949840b65059aae90589862809318e1b95959 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 1 Oct 2022 07:52:26 -0700 Subject: [PATCH 1/2] Use readonly over getter for exposing events Fixes #4164 --- .../xterm-addon-canvas/src/CanvasRenderer.ts | 2 +- addons/xterm-addon-webgl/src/WebglAddon.ts | 4 +-- addons/xterm-addon-webgl/src/WebglRenderer.ts | 7 +++-- .../typings/xterm-addon-webgl.d.ts | 4 +-- src/browser/Linkifier2.ts | 4 +-- src/browser/Terminal.ts | 20 +++++++------- src/browser/renderer/dom/DomRenderer.ts | 2 +- src/browser/services/CharSizeService.ts | 2 +- src/browser/services/RenderService.ts | 8 +++--- src/browser/services/SelectionService.ts | 8 +++--- src/common/CircularList.ts | 6 ++--- src/common/CoreTerminal.ts | 13 +++++----- src/common/InputHandler.ts | 26 +++++++++---------- src/common/buffer/BufferSet.ts | 2 +- src/common/buffer/Marker.ts | 2 +- src/common/input/WriteBuffer.ts | 3 ++- src/common/public/BufferNamespaceApi.ts | 3 ++- src/common/services/BufferService.ts | 4 +-- src/common/services/CoreMouseService.ts | 11 +++----- src/common/services/CoreService.ts | 6 ++--- src/common/services/DecorationService.ts | 6 ++--- src/common/services/OptionsService.ts | 2 +- src/common/services/UnicodeService.ts | 3 ++- src/headless/Terminal.ts | 11 ++++---- 24 files changed, 78 insertions(+), 81 deletions(-) diff --git a/addons/xterm-addon-canvas/src/CanvasRenderer.ts b/addons/xterm-addon-canvas/src/CanvasRenderer.ts index b642efbc..68475829 100644 --- a/addons/xterm-addon-canvas/src/CanvasRenderer.ts +++ b/addons/xterm-addon-canvas/src/CanvasRenderer.ts @@ -28,7 +28,7 @@ export class CanvasRenderer extends Disposable implements IRenderer { public dimensions: IRenderDimensions; private _onRequestRedraw = new EventEmitter(); - public get onRequestRedraw(): IEvent { return this._onRequestRedraw.event; } + public readonly onRequestRedraw = this._onRequestRedraw.event; constructor( private _colors: IColorSet, diff --git a/addons/xterm-addon-webgl/src/WebglAddon.ts b/addons/xterm-addon-webgl/src/WebglAddon.ts index 5b98a048..a96e7c64 100644 --- a/addons/xterm-addon-webgl/src/WebglAddon.ts +++ b/addons/xterm-addon-webgl/src/WebglAddon.ts @@ -16,9 +16,9 @@ export class WebglAddon implements ITerminalAddon { private _renderer?: WebglRenderer; private _onChangeTextureAtlas = new EventEmitter(); - public get onChangeTextureAtlas(): IEvent { return this._onChangeTextureAtlas.event; } + public readonly onChangeTextureAtlas = this._onChangeTextureAtlas.event; private _onContextLoss = new EventEmitter(); - public get onContextLoss(): IEvent { return this._onContextLoss.event; } + public readonly onContextLoss = this._onContextLoss.event; constructor( private _preserveDrawingBuffer?: boolean diff --git a/addons/xterm-addon-webgl/src/WebglRenderer.ts b/addons/xterm-addon-webgl/src/WebglRenderer.ts index d8daa0d1..74488c6c 100644 --- a/addons/xterm-addon-webgl/src/WebglRenderer.ts +++ b/addons/xterm-addon-webgl/src/WebglRenderer.ts @@ -56,12 +56,11 @@ export class WebglRenderer extends Disposable implements IRenderer { private _contextRestorationTimeout: number | undefined; private _onChangeTextureAtlas = new EventEmitter(); - public get onChangeTextureAtlas(): IEvent { return this._onChangeTextureAtlas.event; } + public readonly onChangeTextureAtlas = this._onChangeTextureAtlas.event; private _onRequestRedraw = new EventEmitter(); - public get onRequestRedraw(): IEvent { return this._onRequestRedraw.event; } - + public readonly onRequestRedraw = this._onRequestRedraw.event; private _onContextLoss = new EventEmitter(); - public get onContextLoss(): IEvent { return this._onContextLoss.event; } + public readonly onContextLoss = this._onContextLoss.event; constructor( private _terminal: Terminal, diff --git a/addons/xterm-addon-webgl/typings/xterm-addon-webgl.d.ts b/addons/xterm-addon-webgl/typings/xterm-addon-webgl.d.ts index 74aed0cc..6865b6db 100644 --- a/addons/xterm-addon-webgl/typings/xterm-addon-webgl.d.ts +++ b/addons/xterm-addon-webgl/typings/xterm-addon-webgl.d.ts @@ -15,12 +15,12 @@ declare module 'xterm-addon-webgl' { /** * An event that is fired when the renderer loses its canvas context. */ - public get onContextLoss(): IEvent; + public readonly onContextLoss: IEvent; /** * An event that is fired when the texture atlas of the renderer changes. */ - public get onChangeTextureAtlas(): IEvent; + public readonly onChangeTextureAtlas: IEvent; constructor(preserveDrawingBuffer?: boolean); diff --git a/src/browser/Linkifier2.ts b/src/browser/Linkifier2.ts index 9c978949..6bf9fe23 100644 --- a/src/browser/Linkifier2.ts +++ b/src/browser/Linkifier2.ts @@ -27,9 +27,9 @@ export class Linkifier2 extends Disposable implements ILinkifier2 { private _activeLine: number = -1; private _onShowLinkUnderline = this.register(new EventEmitter()); - public get onShowLinkUnderline(): IEvent { return this._onShowLinkUnderline.event; } + public readonly onShowLinkUnderline = this._onShowLinkUnderline.event; private _onHideLinkUnderline = this.register(new EventEmitter()); - public get onHideLinkUnderline(): IEvent { return this._onHideLinkUnderline.event; } + public readonly onHideLinkUnderline = this._onHideLinkUnderline.event; constructor( @IBufferService private readonly _bufferService: IBufferService diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index afdac748..e03be89c 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -123,26 +123,26 @@ export class Terminal extends CoreTerminal implements ITerminal { private _theme: ITheme | undefined; private _onCursorMove = new EventEmitter(); - public get onCursorMove(): IEvent { return this._onCursorMove.event; } + public readonly onCursorMove = this._onCursorMove.event; private _onKey = new EventEmitter<{ key: string, domEvent: KeyboardEvent }>(); - public get onKey(): IEvent<{ key: string, domEvent: KeyboardEvent }> { return this._onKey.event; } + public readonly onKey = this._onKey.event; private _onRender = new EventEmitter<{ start: number, end: number }>(); - public get onRender(): IEvent<{ start: number, end: number }> { return this._onRender.event; } + public readonly onRender = this._onRender.event; private _onSelectionChange = new EventEmitter(); - public get onSelectionChange(): IEvent { return this._onSelectionChange.event; } + public readonly onSelectionChange = this._onSelectionChange.event; private _onTitleChange = new EventEmitter(); - public get onTitleChange(): IEvent { return this._onTitleChange.event; } + public readonly onTitleChange = this._onTitleChange.event; private _onBell = new EventEmitter(); - public get onBell(): IEvent { return this._onBell.event; } + public readonly onBell = this._onBell.event; private _onFocus = new EventEmitter(); - public get onFocus(): IEvent { return this._onFocus.event; } + public readonly onFocus = this._onFocus.event; private _onBlur = new EventEmitter(); - public get onBlur(): IEvent { return this._onBlur.event; } + public readonly onBlur = this._onBlur.event; private _onA11yCharEmitter = new EventEmitter(); - public get onA11yChar(): IEvent { return this._onA11yCharEmitter.event; } + public readonly onA11yChar = this._onA11yCharEmitter.event; private _onA11yTabEmitter = new EventEmitter(); - public get onA11yTab(): IEvent { return this._onA11yTabEmitter.event; } + public readonly onA11yTab = this._onA11yTabEmitter.event; /** * Creates a new `Terminal` object. diff --git a/src/browser/renderer/dom/DomRenderer.ts b/src/browser/renderer/dom/DomRenderer.ts index 8df6b302..223e2470 100644 --- a/src/browser/renderer/dom/DomRenderer.ts +++ b/src/browser/renderer/dom/DomRenderer.ts @@ -40,7 +40,7 @@ export class DomRenderer extends Disposable implements IRenderer { public dimensions: IRenderDimensions; - public get onRequestRedraw(): IEvent { return new EventEmitter().event; } + public readonly onRequestRedraw = new EventEmitter().event; constructor( private _colors: IColorSet, diff --git a/src/browser/services/CharSizeService.ts b/src/browser/services/CharSizeService.ts index b04e157f..d5cc37c8 100644 --- a/src/browser/services/CharSizeService.ts +++ b/src/browser/services/CharSizeService.ts @@ -17,7 +17,7 @@ export class CharSizeService implements ICharSizeService { public get hasValidSize(): boolean { return this.width > 0 && this.height > 0; } private _onCharSizeChange = new EventEmitter(); - public get onCharSizeChange(): IEvent { return this._onCharSizeChange.event; } + public readonly onCharSizeChange = this._onCharSizeChange.event; constructor( document: Document, diff --git a/src/browser/services/RenderService.ts b/src/browser/services/RenderService.ts index 97258609..69213429 100644 --- a/src/browser/services/RenderService.ts +++ b/src/browser/services/RenderService.ts @@ -40,13 +40,13 @@ export class RenderService extends Disposable implements IRenderService { }; private _onDimensionsChange = new EventEmitter(); - public get onDimensionsChange(): IEvent { return this._onDimensionsChange.event; } + public readonly onDimensionsChange = this._onDimensionsChange.event; private _onRenderedViewportChange = new EventEmitter<{ start: number, end: number }>(); - public get onRenderedViewportChange(): IEvent<{ start: number, end: number }> { return this._onRenderedViewportChange.event; } + public readonly onRenderedViewportChange = this._onRenderedViewportChange.event; private _onRender = new EventEmitter<{ start: number, end: number }>(); - public get onRender(): IEvent<{ start: number, end: number }> { return this._onRender.event; } + public readonly onRender = this._onRender.event; private _onRefreshRequest = new EventEmitter<{ start: number, end: number }>(); - public get onRefreshRequest(): IEvent<{ start: number, end: number }> { return this._onRefreshRequest.event; } + public readonly onRefreshRequest = this._onRefreshRequest.event; public get dimensions(): IRenderDimensions { return this._renderer.dimensions; } diff --git a/src/browser/services/SelectionService.ts b/src/browser/services/SelectionService.ts index 4ee1ffa1..29c8e664 100644 --- a/src/browser/services/SelectionService.ts +++ b/src/browser/services/SelectionService.ts @@ -112,13 +112,13 @@ export class SelectionService extends Disposable implements ISelectionService { private _oldSelectionEnd: [number, number] | undefined = undefined; private _onLinuxMouseSelection = this.register(new EventEmitter()); - public get onLinuxMouseSelection(): IEvent { return this._onLinuxMouseSelection.event; } + public readonly onLinuxMouseSelection = this._onLinuxMouseSelection.event; private _onRedrawRequest = this.register(new EventEmitter()); - public get onRequestRedraw(): IEvent { return this._onRedrawRequest.event; } + public readonly onRequestRedraw = this._onRedrawRequest.event; private _onSelectionChange = this.register(new EventEmitter()); - public get onSelectionChange(): IEvent { return this._onSelectionChange.event; } + public readonly onSelectionChange = this._onSelectionChange.event; private _onRequestScrollLines = this.register(new EventEmitter()); - public get onRequestScrollLines(): IEvent { return this._onRequestScrollLines.event; } + public readonly onRequestScrollLines = this._onRequestScrollLines.event; constructor( private readonly _element: HTMLElement, diff --git a/src/common/CircularList.ts b/src/common/CircularList.ts index 4d2c04ec..c0c6bb5b 100644 --- a/src/common/CircularList.ts +++ b/src/common/CircularList.ts @@ -26,11 +26,11 @@ export class CircularList implements ICircularList { private _length: number; public onDeleteEmitter = new EventEmitter(); - public get onDelete(): IEvent { return this.onDeleteEmitter.event; } + public readonly onDelete = this.onDeleteEmitter.event; public onInsertEmitter = new EventEmitter(); - public get onInsert(): IEvent { return this.onInsertEmitter.event; } + public readonly onInsert = this.onInsertEmitter.event; public onTrimEmitter = new EventEmitter(); - public get onTrim(): IEvent { return this.onTrimEmitter.event; } + public readonly onTrim = this.onTrimEmitter.event; constructor( private _maxLength: number diff --git a/src/common/CoreTerminal.ts b/src/common/CoreTerminal.ts index 02a94392..da70f84a 100644 --- a/src/common/CoreTerminal.ts +++ b/src/common/CoreTerminal.ts @@ -62,21 +62,22 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal { private _windowsMode: IDisposable | undefined; private _onBinary = new EventEmitter(); - public get onBinary(): IEvent { return this._onBinary.event; } + public readonly onBinary = this._onBinary.event; private _onData = new EventEmitter(); - public get onData(): IEvent { return this._onData.event; } + public readonly onData = this._onData.event; protected _onLineFeed = new EventEmitter(); - public get onLineFeed(): IEvent { return this._onLineFeed.event; } + public readonly onLineFeed = this._onLineFeed.event; private _onResize = new EventEmitter<{ cols: number, rows: number }>(); - public get onResize(): IEvent<{ cols: number, rows: number }> { return this._onResize.event; } - protected _onScroll = new EventEmitter(); - public get onWriteParsed(): IEvent { return this._onWriteParsed.event; } + public readonly onResize = this._onResize.event; protected _onWriteParsed = new EventEmitter(); + public readonly onWriteParsed = this._onWriteParsed.event; + /** * Internally we track the source of the scroll but this is meaningless outside the library so * it's filtered out. */ protected _onScrollApi?: EventEmitter; + protected _onScroll = new EventEmitter(); public get onScroll(): IEvent { if (!this._onScrollApi) { this._onScrollApi = new EventEmitter(); diff --git a/src/common/InputHandler.ts b/src/common/InputHandler.ts index b599bb7e..bcdb2065 100644 --- a/src/common/InputHandler.ts +++ b/src/common/InputHandler.ts @@ -130,32 +130,32 @@ export class InputHandler extends Disposable implements IInputHandler { private _activeBuffer: IBuffer; private _onRequestBell = new EventEmitter(); - public get onRequestBell(): IEvent { return this._onRequestBell.event; } + public readonly onRequestBell = this._onRequestBell.event; private _onRequestRefreshRows = new EventEmitter(); - public get onRequestRefreshRows(): IEvent { return this._onRequestRefreshRows.event; } + public readonly onRequestRefreshRows = this._onRequestRefreshRows.event; private _onRequestReset = new EventEmitter(); - public get onRequestReset(): IEvent { return this._onRequestReset.event; } + public readonly onRequestReset = this._onRequestReset.event; private _onRequestSendFocus = new EventEmitter(); - public get onRequestSendFocus(): IEvent { return this._onRequestSendFocus.event; } + public readonly onRequestSendFocus = this._onRequestSendFocus.event; private _onRequestSyncScrollBar = new EventEmitter(); - public get onRequestSyncScrollBar(): IEvent { return this._onRequestSyncScrollBar.event; } + public readonly onRequestSyncScrollBar = this._onRequestSyncScrollBar.event; private _onRequestWindowsOptionsReport = new EventEmitter(); - public get onRequestWindowsOptionsReport(): IEvent { return this._onRequestWindowsOptionsReport.event; } + public readonly onRequestWindowsOptionsReport = this._onRequestWindowsOptionsReport.event; private _onA11yChar = new EventEmitter(); - public get onA11yChar(): IEvent { return this._onA11yChar.event; } + public readonly onA11yChar = this._onA11yChar.event; private _onA11yTab = new EventEmitter(); - public get onA11yTab(): IEvent { return this._onA11yTab.event; } + public readonly onA11yTab = this._onA11yTab.event; private _onCursorMove = new EventEmitter(); - public get onCursorMove(): IEvent { return this._onCursorMove.event; } + public readonly onCursorMove = this._onCursorMove.event; private _onLineFeed = new EventEmitter(); - public get onLineFeed(): IEvent { return this._onLineFeed.event; } + public readonly onLineFeed = this._onLineFeed.event; private _onScroll = new EventEmitter(); - public get onScroll(): IEvent { return this._onScroll.event; } + public readonly onScroll = this._onScroll.event; private _onTitleChange = new EventEmitter(); - public get onTitleChange(): IEvent { return this._onTitleChange.event; } + public readonly onTitleChange = this._onTitleChange.event; private _onColor = new EventEmitter(); - public get onColor(): IEvent { return this._onColor.event; } + public readonly onColor = this._onColor.event; private _parseStack: IParseStack = { paused: false, diff --git a/src/common/buffer/BufferSet.ts b/src/common/buffer/BufferSet.ts index f940bb8f..b2223b03 100644 --- a/src/common/buffer/BufferSet.ts +++ b/src/common/buffer/BufferSet.ts @@ -20,7 +20,7 @@ export class BufferSet extends Disposable implements IBufferSet { private _activeBuffer!: Buffer; private _onBufferActivate = this.register(new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>()); - public get onBufferActivate(): IEvent<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}> { return this._onBufferActivate.event; } + public readonly onBufferActivate = this._onBufferActivate.event; /** * Create a new BufferSet for the given terminal. diff --git a/src/common/buffer/Marker.ts b/src/common/buffer/Marker.ts index 72c4085c..9737b389 100644 --- a/src/common/buffer/Marker.ts +++ b/src/common/buffer/Marker.ts @@ -16,7 +16,7 @@ export class Marker extends Disposable implements IMarker { public get id(): number { return this._id; } private _onDispose = new EventEmitter(); - public get onDispose(): IEvent { return this._onDispose.event; } + public readonly onDispose = this._onDispose.event; constructor( public line: number diff --git a/src/common/input/WriteBuffer.ts b/src/common/input/WriteBuffer.ts index 4f316f24..9f816d6c 100644 --- a/src/common/input/WriteBuffer.ts +++ b/src/common/input/WriteBuffer.ts @@ -41,8 +41,9 @@ export class WriteBuffer { private _isSyncWriting = false; private _syncCalls = 0; private _didUserInput = false; - public get onWriteParsed(): IEvent { return this._onWriteParsed.event; } + private _onWriteParsed = new EventEmitter(); + public readonly onWriteParsed = this._onWriteParsed.event; constructor(private _action: (data: string | Uint8Array, promiseResult?: boolean) => void | Promise) { } diff --git a/src/common/public/BufferNamespaceApi.ts b/src/common/public/BufferNamespaceApi.ts index d86f6bf5..f331a0b7 100644 --- a/src/common/public/BufferNamespaceApi.ts +++ b/src/common/public/BufferNamespaceApi.ts @@ -11,8 +11,9 @@ import { ICoreTerminal } from 'common/Types'; export class BufferNamespaceApi implements IBufferNamespaceApi { private _normal: BufferApiView; private _alternate: BufferApiView; + private _onBufferChange = new EventEmitter(); - public get onBufferChange(): IEvent { return this._onBufferChange.event; } + public readonly onBufferChange = this._onBufferChange.event; constructor(private _core: ICoreTerminal) { this._normal = new BufferApiView(this._core.buffers.normal, 'normal'); diff --git a/src/common/services/BufferService.ts b/src/common/services/BufferService.ts index e3b7dcd8..49f31147 100644 --- a/src/common/services/BufferService.ts +++ b/src/common/services/BufferService.ts @@ -23,9 +23,9 @@ export class BufferService extends Disposable implements IBufferService { public isUserScrolling: boolean = false; private _onResize = new EventEmitter<{ cols: number, rows: number }>(); - public get onResize(): IEvent<{ cols: number, rows: number }> { return this._onResize.event; } + public readonly onResize = this._onResize.event; private _onScroll = new EventEmitter(); - public get onScroll(): IEvent { return this._onScroll.event; } + public readonly onScroll = this._onScroll.event; public get buffer(): IBuffer { return this.buffers.active; } diff --git a/src/common/services/CoreMouseService.ts b/src/common/services/CoreMouseService.ts index 54e991f8..465a4968 100644 --- a/src/common/services/CoreMouseService.ts +++ b/src/common/services/CoreMouseService.ts @@ -170,9 +170,11 @@ export class CoreMouseService implements ICoreMouseService { private _encodings: { [name: string]: CoreMouseEncoding } = {}; private _activeProtocol: string = ''; private _activeEncoding: string = ''; - private _onProtocolChange = new EventEmitter(); private _lastEvent: ICoreMouseEvent | null = null; + private _onProtocolChange = new EventEmitter(); + public readonly onProtocolChange = this._onProtocolChange.event; + constructor( @IBufferService private readonly _bufferService: IBufferService, @ICoreService private readonly _coreService: ICoreService @@ -225,13 +227,6 @@ export class CoreMouseService implements ICoreMouseService { this._lastEvent = null; } - /** - * Event to announce changes in mouse tracking. - */ - public get onProtocolChange(): IEvent { - return this._onProtocolChange.event; - } - /** * Triggers a mouse event to be sent. * diff --git a/src/common/services/CoreService.ts b/src/common/services/CoreService.ts index 20a34603..a144eb1d 100644 --- a/src/common/services/CoreService.ts +++ b/src/common/services/CoreService.ts @@ -35,11 +35,11 @@ export class CoreService extends Disposable implements ICoreService { private _scrollToBottom: (() => void) | undefined; private _onData = this.register(new EventEmitter()); - public get onData(): IEvent { return this._onData.event; } + public readonly onData = this._onData.event; private _onUserInput = this.register(new EventEmitter()); - public get onUserInput(): IEvent { return this._onUserInput.event; } + public readonly onUserInput = this._onUserInput.event; private _onBinary = this.register(new EventEmitter()); - public get onBinary(): IEvent { return this._onBinary.event; } + public readonly onBinary = this._onBinary.event; constructor( // TODO: Move this into a service diff --git a/src/common/services/DecorationService.ts b/src/common/services/DecorationService.ts index e5d115a1..d0f9b991 100644 --- a/src/common/services/DecorationService.ts +++ b/src/common/services/DecorationService.ts @@ -28,9 +28,9 @@ export class DecorationService extends Disposable implements IDecorationService private readonly _decorations: SortedList = new SortedList(e => e?.marker.line); private _onDecorationRegistered = this.register(new EventEmitter()); - public get onDecorationRegistered(): IEvent { return this._onDecorationRegistered.event; } + public readonly onDecorationRegistered = this._onDecorationRegistered.event; private _onDecorationRemoved = this.register(new EventEmitter()); - public get onDecorationRemoved(): IEvent { return this._onDecorationRemoved.event; } + public readonly onDecorationRemoved = this._onDecorationRemoved.event; public get decorations(): IterableIterator { return this._decorations.values(); } @@ -99,7 +99,7 @@ class Decoration extends Disposable implements IInternalDecoration { public readonly onRenderEmitter = this.register(new EventEmitter()); public readonly onRender = this.onRenderEmitter.event; - private _onDispose = this.register(new EventEmitter()); + private readonly _onDispose = this.register(new EventEmitter()); public readonly onDispose = this._onDispose.event; private _cachedBg: IColor | undefined | null = null; diff --git a/src/common/services/OptionsService.ts b/src/common/services/OptionsService.ts index c7e8d294..d6662c31 100644 --- a/src/common/services/OptionsService.ts +++ b/src/common/services/OptionsService.ts @@ -58,7 +58,7 @@ export class OptionsService implements IOptionsService { public options: Required; private _onOptionChange = new EventEmitter(); - public get onOptionChange(): IEvent { return this._onOptionChange.event; } + public readonly onOptionChange = this._onOptionChange.event; constructor(options: Partial) { // set the default value of each option diff --git a/src/common/services/UnicodeService.ts b/src/common/services/UnicodeService.ts index e96b7579..b5d19623 100644 --- a/src/common/services/UnicodeService.ts +++ b/src/common/services/UnicodeService.ts @@ -13,8 +13,9 @@ export class UnicodeService implements IUnicodeService { private _providers: {[key: string]: IUnicodeVersionProvider} = Object.create(null); private _active: string = ''; private _activeProvider: IUnicodeVersionProvider; + private _onChange = new EventEmitter(); - public get onChange(): IEvent { return this._onChange.event; } + public readonly onChange = this._onChange.event; constructor() { const defaultProvider = new UnicodeV6(); diff --git a/src/headless/Terminal.ts b/src/headless/Terminal.ts index 1cad0ee2..1b1162e5 100644 --- a/src/headless/Terminal.ts +++ b/src/headless/Terminal.ts @@ -33,16 +33,15 @@ export class Terminal extends CoreTerminal { public get options(): Required { return this.optionsService.options; } private _onBell = new EventEmitter(); - public get onBell(): IEvent { return this._onBell.event; } + public readonly onBell = this._onBell.event; private _onCursorMove = new EventEmitter(); - public get onCursorMove(): IEvent { return this._onCursorMove.event; } + public readonly onCursorMove = this._onCursorMove.event; private _onTitleChange = new EventEmitter(); - public get onTitleChange(): IEvent { return this._onTitleChange.event; } - + public readonly onTitleChange = this._onTitleChange.event; private _onA11yCharEmitter = new EventEmitter(); - public get onA11yChar(): IEvent { return this._onA11yCharEmitter.event; } + public readonly onA11yChar = this._onA11yCharEmitter.event; private _onA11yTabEmitter = new EventEmitter(); - public get onA11yTab(): IEvent { return this._onA11yTabEmitter.event; } + public readonly onA11yTab = this._onA11yTabEmitter.event; /** * Creates a new `Terminal` object. From 1a22c44f2b7ca10d23755c86b78d3361fa2570be Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 1 Oct 2022 08:02:32 -0700 Subject: [PATCH 2/2] Make all emitters readonly --- .../xterm-addon-canvas/src/CanvasRenderer.ts | 2 +- addons/xterm-addon-webgl/src/WebglAddon.ts | 4 +-- addons/xterm-addon-webgl/src/WebglRenderer.ts | 6 ++--- src/browser/Linkifier2.ts | 4 +-- src/browser/Terminal.ts | 20 +++++++------- src/browser/services/CharSizeService.ts | 2 +- src/browser/services/RenderService.ts | 8 +++--- src/browser/services/SelectionService.ts | 8 +++--- src/common/CircularList.ts | 6 ++--- src/common/CoreTerminal.ts | 8 +++--- src/common/InputHandler.ts | 26 +++++++++---------- src/common/buffer/BufferSet.ts | 2 +- src/common/buffer/Marker.ts | 2 +- src/common/input/WriteBuffer.ts | 2 +- src/common/public/BufferNamespaceApi.ts | 2 +- src/common/services/BufferService.ts | 6 ++--- src/common/services/CoreMouseService.ts | 2 +- src/common/services/CoreService.ts | 6 ++--- src/common/services/DecorationService.ts | 4 +-- src/common/services/OptionsService.ts | 2 +- src/common/services/UnicodeService.ts | 2 +- src/headless/Terminal.ts | 10 +++---- 22 files changed, 67 insertions(+), 67 deletions(-) diff --git a/addons/xterm-addon-canvas/src/CanvasRenderer.ts b/addons/xterm-addon-canvas/src/CanvasRenderer.ts index 68475829..fd9629c0 100644 --- a/addons/xterm-addon-canvas/src/CanvasRenderer.ts +++ b/addons/xterm-addon-canvas/src/CanvasRenderer.ts @@ -27,7 +27,7 @@ export class CanvasRenderer extends Disposable implements IRenderer { public dimensions: IRenderDimensions; - private _onRequestRedraw = new EventEmitter(); + private readonly _onRequestRedraw = new EventEmitter(); public readonly onRequestRedraw = this._onRequestRedraw.event; constructor( diff --git a/addons/xterm-addon-webgl/src/WebglAddon.ts b/addons/xterm-addon-webgl/src/WebglAddon.ts index a96e7c64..45858e8c 100644 --- a/addons/xterm-addon-webgl/src/WebglAddon.ts +++ b/addons/xterm-addon-webgl/src/WebglAddon.ts @@ -15,9 +15,9 @@ export class WebglAddon implements ITerminalAddon { private _terminal?: Terminal; private _renderer?: WebglRenderer; - private _onChangeTextureAtlas = new EventEmitter(); + private readonly _onChangeTextureAtlas = new EventEmitter(); public readonly onChangeTextureAtlas = this._onChangeTextureAtlas.event; - private _onContextLoss = new EventEmitter(); + private readonly _onContextLoss = new EventEmitter(); public readonly onContextLoss = this._onContextLoss.event; constructor( diff --git a/addons/xterm-addon-webgl/src/WebglRenderer.ts b/addons/xterm-addon-webgl/src/WebglRenderer.ts index 74488c6c..0fc634a7 100644 --- a/addons/xterm-addon-webgl/src/WebglRenderer.ts +++ b/addons/xterm-addon-webgl/src/WebglRenderer.ts @@ -55,11 +55,11 @@ export class WebglRenderer extends Disposable implements IRenderer { private _isAttached: boolean; private _contextRestorationTimeout: number | undefined; - private _onChangeTextureAtlas = new EventEmitter(); + private readonly _onChangeTextureAtlas = new EventEmitter(); public readonly onChangeTextureAtlas = this._onChangeTextureAtlas.event; - private _onRequestRedraw = new EventEmitter(); + private readonly _onRequestRedraw = new EventEmitter(); public readonly onRequestRedraw = this._onRequestRedraw.event; - private _onContextLoss = new EventEmitter(); + private readonly _onContextLoss = new EventEmitter(); public readonly onContextLoss = this._onContextLoss.event; constructor( diff --git a/src/browser/Linkifier2.ts b/src/browser/Linkifier2.ts index 6bf9fe23..cf5b9dd2 100644 --- a/src/browser/Linkifier2.ts +++ b/src/browser/Linkifier2.ts @@ -26,9 +26,9 @@ export class Linkifier2 extends Disposable implements ILinkifier2 { private _activeProviderReplies: Map | undefined; private _activeLine: number = -1; - private _onShowLinkUnderline = this.register(new EventEmitter()); + private readonly _onShowLinkUnderline = this.register(new EventEmitter()); public readonly onShowLinkUnderline = this._onShowLinkUnderline.event; - private _onHideLinkUnderline = this.register(new EventEmitter()); + private readonly _onHideLinkUnderline = this.register(new EventEmitter()); public readonly onHideLinkUnderline = this._onHideLinkUnderline.event; constructor( diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index e03be89c..9c10fc16 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -122,26 +122,26 @@ export class Terminal extends CoreTerminal implements ITerminal { private _colorManager: ColorManager | undefined; private _theme: ITheme | undefined; - private _onCursorMove = new EventEmitter(); + private readonly _onCursorMove = new EventEmitter(); public readonly onCursorMove = this._onCursorMove.event; - private _onKey = new EventEmitter<{ key: string, domEvent: KeyboardEvent }>(); + private readonly _onKey = new EventEmitter<{ key: string, domEvent: KeyboardEvent }>(); public readonly onKey = this._onKey.event; - private _onRender = new EventEmitter<{ start: number, end: number }>(); + private readonly _onRender = new EventEmitter<{ start: number, end: number }>(); public readonly onRender = this._onRender.event; - private _onSelectionChange = new EventEmitter(); + private readonly _onSelectionChange = new EventEmitter(); public readonly onSelectionChange = this._onSelectionChange.event; - private _onTitleChange = new EventEmitter(); + private readonly _onTitleChange = new EventEmitter(); public readonly onTitleChange = this._onTitleChange.event; - private _onBell = new EventEmitter(); + private readonly _onBell = new EventEmitter(); public readonly onBell = this._onBell.event; - private _onFocus = new EventEmitter(); + private readonly _onFocus = new EventEmitter(); public readonly onFocus = this._onFocus.event; - private _onBlur = new EventEmitter(); + private readonly _onBlur = new EventEmitter(); public readonly onBlur = this._onBlur.event; - private _onA11yCharEmitter = new EventEmitter(); + private readonly _onA11yCharEmitter = new EventEmitter(); public readonly onA11yChar = this._onA11yCharEmitter.event; - private _onA11yTabEmitter = new EventEmitter(); + private readonly _onA11yTabEmitter = new EventEmitter(); public readonly onA11yTab = this._onA11yTabEmitter.event; /** diff --git a/src/browser/services/CharSizeService.ts b/src/browser/services/CharSizeService.ts index d5cc37c8..7062deec 100644 --- a/src/browser/services/CharSizeService.ts +++ b/src/browser/services/CharSizeService.ts @@ -16,7 +16,7 @@ export class CharSizeService implements ICharSizeService { public get hasValidSize(): boolean { return this.width > 0 && this.height > 0; } - private _onCharSizeChange = new EventEmitter(); + private readonly _onCharSizeChange = new EventEmitter(); public readonly onCharSizeChange = this._onCharSizeChange.event; constructor( diff --git a/src/browser/services/RenderService.ts b/src/browser/services/RenderService.ts index 69213429..66dbb7aa 100644 --- a/src/browser/services/RenderService.ts +++ b/src/browser/services/RenderService.ts @@ -39,13 +39,13 @@ export class RenderService extends Disposable implements IRenderService { columnSelectMode: false }; - private _onDimensionsChange = new EventEmitter(); + private readonly _onDimensionsChange = new EventEmitter(); public readonly onDimensionsChange = this._onDimensionsChange.event; - private _onRenderedViewportChange = new EventEmitter<{ start: number, end: number }>(); + private readonly _onRenderedViewportChange = new EventEmitter<{ start: number, end: number }>(); public readonly onRenderedViewportChange = this._onRenderedViewportChange.event; - private _onRender = new EventEmitter<{ start: number, end: number }>(); + private readonly _onRender = new EventEmitter<{ start: number, end: number }>(); public readonly onRender = this._onRender.event; - private _onRefreshRequest = new EventEmitter<{ start: number, end: number }>(); + private readonly _onRefreshRequest = new EventEmitter<{ start: number, end: number }>(); public readonly onRefreshRequest = this._onRefreshRequest.event; public get dimensions(): IRenderDimensions { return this._renderer.dimensions; } diff --git a/src/browser/services/SelectionService.ts b/src/browser/services/SelectionService.ts index 29c8e664..3780c7ee 100644 --- a/src/browser/services/SelectionService.ts +++ b/src/browser/services/SelectionService.ts @@ -111,13 +111,13 @@ export class SelectionService extends Disposable implements ISelectionService { private _oldSelectionStart: [number, number] | undefined = undefined; private _oldSelectionEnd: [number, number] | undefined = undefined; - private _onLinuxMouseSelection = this.register(new EventEmitter()); + private readonly _onLinuxMouseSelection = this.register(new EventEmitter()); public readonly onLinuxMouseSelection = this._onLinuxMouseSelection.event; - private _onRedrawRequest = this.register(new EventEmitter()); + private readonly _onRedrawRequest = this.register(new EventEmitter()); public readonly onRequestRedraw = this._onRedrawRequest.event; - private _onSelectionChange = this.register(new EventEmitter()); + private readonly _onSelectionChange = this.register(new EventEmitter()); public readonly onSelectionChange = this._onSelectionChange.event; - private _onRequestScrollLines = this.register(new EventEmitter()); + private readonly _onRequestScrollLines = this.register(new EventEmitter()); public readonly onRequestScrollLines = this._onRequestScrollLines.event; constructor( diff --git a/src/common/CircularList.ts b/src/common/CircularList.ts index c0c6bb5b..599db1ab 100644 --- a/src/common/CircularList.ts +++ b/src/common/CircularList.ts @@ -25,11 +25,11 @@ export class CircularList implements ICircularList { private _startIndex: number; private _length: number; - public onDeleteEmitter = new EventEmitter(); + public readonly onDeleteEmitter = new EventEmitter(); public readonly onDelete = this.onDeleteEmitter.event; - public onInsertEmitter = new EventEmitter(); + public readonly onInsertEmitter = new EventEmitter(); public readonly onInsert = this.onInsertEmitter.event; - public onTrimEmitter = new EventEmitter(); + public readonly onTrimEmitter = new EventEmitter(); public readonly onTrim = this.onTrimEmitter.event; constructor( diff --git a/src/common/CoreTerminal.ts b/src/common/CoreTerminal.ts index da70f84a..3a17c567 100644 --- a/src/common/CoreTerminal.ts +++ b/src/common/CoreTerminal.ts @@ -61,15 +61,15 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal { private _writeBuffer: WriteBuffer; private _windowsMode: IDisposable | undefined; - private _onBinary = new EventEmitter(); + private readonly _onBinary = new EventEmitter(); public readonly onBinary = this._onBinary.event; - private _onData = new EventEmitter(); + private readonly _onData = new EventEmitter(); public readonly onData = this._onData.event; protected _onLineFeed = new EventEmitter(); public readonly onLineFeed = this._onLineFeed.event; - private _onResize = new EventEmitter<{ cols: number, rows: number }>(); + private readonly _onResize = new EventEmitter<{ cols: number, rows: number }>(); public readonly onResize = this._onResize.event; - protected _onWriteParsed = new EventEmitter(); + protected readonly _onWriteParsed = new EventEmitter(); public readonly onWriteParsed = this._onWriteParsed.event; /** diff --git a/src/common/InputHandler.ts b/src/common/InputHandler.ts index bcdb2065..0ace846a 100644 --- a/src/common/InputHandler.ts +++ b/src/common/InputHandler.ts @@ -129,32 +129,32 @@ export class InputHandler extends Disposable implements IInputHandler { private _activeBuffer: IBuffer; - private _onRequestBell = new EventEmitter(); + private readonly _onRequestBell = new EventEmitter(); public readonly onRequestBell = this._onRequestBell.event; - private _onRequestRefreshRows = new EventEmitter(); + private readonly _onRequestRefreshRows = new EventEmitter(); public readonly onRequestRefreshRows = this._onRequestRefreshRows.event; - private _onRequestReset = new EventEmitter(); + private readonly _onRequestReset = new EventEmitter(); public readonly onRequestReset = this._onRequestReset.event; - private _onRequestSendFocus = new EventEmitter(); + private readonly _onRequestSendFocus = new EventEmitter(); public readonly onRequestSendFocus = this._onRequestSendFocus.event; - private _onRequestSyncScrollBar = new EventEmitter(); + private readonly _onRequestSyncScrollBar = new EventEmitter(); public readonly onRequestSyncScrollBar = this._onRequestSyncScrollBar.event; - private _onRequestWindowsOptionsReport = new EventEmitter(); + private readonly _onRequestWindowsOptionsReport = new EventEmitter(); public readonly onRequestWindowsOptionsReport = this._onRequestWindowsOptionsReport.event; - private _onA11yChar = new EventEmitter(); + private readonly _onA11yChar = new EventEmitter(); public readonly onA11yChar = this._onA11yChar.event; - private _onA11yTab = new EventEmitter(); + private readonly _onA11yTab = new EventEmitter(); public readonly onA11yTab = this._onA11yTab.event; - private _onCursorMove = new EventEmitter(); + private readonly _onCursorMove = new EventEmitter(); public readonly onCursorMove = this._onCursorMove.event; - private _onLineFeed = new EventEmitter(); + private readonly _onLineFeed = new EventEmitter(); public readonly onLineFeed = this._onLineFeed.event; - private _onScroll = new EventEmitter(); + private readonly _onScroll = new EventEmitter(); public readonly onScroll = this._onScroll.event; - private _onTitleChange = new EventEmitter(); + private readonly _onTitleChange = new EventEmitter(); public readonly onTitleChange = this._onTitleChange.event; - private _onColor = new EventEmitter(); + private readonly _onColor = new EventEmitter(); public readonly onColor = this._onColor.event; private _parseStack: IParseStack = { diff --git a/src/common/buffer/BufferSet.ts b/src/common/buffer/BufferSet.ts index b2223b03..46fcb097 100644 --- a/src/common/buffer/BufferSet.ts +++ b/src/common/buffer/BufferSet.ts @@ -19,7 +19,7 @@ export class BufferSet extends Disposable implements IBufferSet { private _alt!: Buffer; private _activeBuffer!: Buffer; - private _onBufferActivate = this.register(new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>()); + private readonly _onBufferActivate = this.register(new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>()); public readonly onBufferActivate = this._onBufferActivate.event; /** diff --git a/src/common/buffer/Marker.ts b/src/common/buffer/Marker.ts index 9737b389..56d64a72 100644 --- a/src/common/buffer/Marker.ts +++ b/src/common/buffer/Marker.ts @@ -15,7 +15,7 @@ export class Marker extends Disposable implements IMarker { public get id(): number { return this._id; } - private _onDispose = new EventEmitter(); + private readonly _onDispose = new EventEmitter(); public readonly onDispose = this._onDispose.event; constructor( diff --git a/src/common/input/WriteBuffer.ts b/src/common/input/WriteBuffer.ts index 9f816d6c..bf72ae21 100644 --- a/src/common/input/WriteBuffer.ts +++ b/src/common/input/WriteBuffer.ts @@ -42,7 +42,7 @@ export class WriteBuffer { private _syncCalls = 0; private _didUserInput = false; - private _onWriteParsed = new EventEmitter(); + private readonly _onWriteParsed = new EventEmitter(); public readonly onWriteParsed = this._onWriteParsed.event; constructor(private _action: (data: string | Uint8Array, promiseResult?: boolean) => void | Promise) { } diff --git a/src/common/public/BufferNamespaceApi.ts b/src/common/public/BufferNamespaceApi.ts index f331a0b7..033f5955 100644 --- a/src/common/public/BufferNamespaceApi.ts +++ b/src/common/public/BufferNamespaceApi.ts @@ -12,7 +12,7 @@ export class BufferNamespaceApi implements IBufferNamespaceApi { private _normal: BufferApiView; private _alternate: BufferApiView; - private _onBufferChange = new EventEmitter(); + private readonly _onBufferChange = new EventEmitter(); public readonly onBufferChange = this._onBufferChange.event; constructor(private _core: ICoreTerminal) { diff --git a/src/common/services/BufferService.ts b/src/common/services/BufferService.ts index 49f31147..1bc93041 100644 --- a/src/common/services/BufferService.ts +++ b/src/common/services/BufferService.ts @@ -6,7 +6,7 @@ import { IBufferService, IOptionsService } from 'common/services/Services'; import { BufferSet } from 'common/buffer/BufferSet'; import { IBufferSet, IBuffer } from 'common/buffer/Types'; -import { EventEmitter, IEvent } from 'common/EventEmitter'; +import { EventEmitter, IEventEmitter, IEvent } from 'common/EventEmitter'; import { Disposable } from 'common/Lifecycle'; import { IAttributeData, IBufferLine, ScrollSource } from 'common/Types'; @@ -22,9 +22,9 @@ export class BufferService extends Disposable implements IBufferService { /** Whether the user is scrolling (locks the scroll position) */ public isUserScrolling: boolean = false; - private _onResize = new EventEmitter<{ cols: number, rows: number }>(); + private readonly _onResize = new EventEmitter<{ cols: number, rows: number }>(); public readonly onResize = this._onResize.event; - private _onScroll = new EventEmitter(); + private readonly _onScroll = new EventEmitter(); public readonly onScroll = this._onScroll.event; public get buffer(): IBuffer { return this.buffers.active; } diff --git a/src/common/services/CoreMouseService.ts b/src/common/services/CoreMouseService.ts index 465a4968..8c2a24de 100644 --- a/src/common/services/CoreMouseService.ts +++ b/src/common/services/CoreMouseService.ts @@ -172,7 +172,7 @@ export class CoreMouseService implements ICoreMouseService { private _activeEncoding: string = ''; private _lastEvent: ICoreMouseEvent | null = null; - private _onProtocolChange = new EventEmitter(); + private readonly _onProtocolChange = new EventEmitter(); public readonly onProtocolChange = this._onProtocolChange.event; constructor( diff --git a/src/common/services/CoreService.ts b/src/common/services/CoreService.ts index a144eb1d..9282197b 100644 --- a/src/common/services/CoreService.ts +++ b/src/common/services/CoreService.ts @@ -34,11 +34,11 @@ export class CoreService extends Disposable implements ICoreService { // Circular dependency, this must be unset or memory will leak after Terminal.dispose private _scrollToBottom: (() => void) | undefined; - private _onData = this.register(new EventEmitter()); + private readonly _onData = this.register(new EventEmitter()); public readonly onData = this._onData.event; - private _onUserInput = this.register(new EventEmitter()); + private readonly _onUserInput = this.register(new EventEmitter()); public readonly onUserInput = this._onUserInput.event; - private _onBinary = this.register(new EventEmitter()); + private readonly _onBinary = this.register(new EventEmitter()); public readonly onBinary = this._onBinary.event; constructor( diff --git a/src/common/services/DecorationService.ts b/src/common/services/DecorationService.ts index d0f9b991..9fb611c6 100644 --- a/src/common/services/DecorationService.ts +++ b/src/common/services/DecorationService.ts @@ -27,9 +27,9 @@ export class DecorationService extends Disposable implements IDecorationService */ private readonly _decorations: SortedList = new SortedList(e => e?.marker.line); - private _onDecorationRegistered = this.register(new EventEmitter()); + private readonly _onDecorationRegistered = this.register(new EventEmitter()); public readonly onDecorationRegistered = this._onDecorationRegistered.event; - private _onDecorationRemoved = this.register(new EventEmitter()); + private readonly _onDecorationRemoved = this.register(new EventEmitter()); public readonly onDecorationRemoved = this._onDecorationRemoved.event; public get decorations(): IterableIterator { return this._decorations.values(); } diff --git a/src/common/services/OptionsService.ts b/src/common/services/OptionsService.ts index d6662c31..33aa3ee2 100644 --- a/src/common/services/OptionsService.ts +++ b/src/common/services/OptionsService.ts @@ -57,7 +57,7 @@ export class OptionsService implements IOptionsService { public readonly rawOptions: Required; public options: Required; - private _onOptionChange = new EventEmitter(); + private readonly _onOptionChange = new EventEmitter(); public readonly onOptionChange = this._onOptionChange.event; constructor(options: Partial) { diff --git a/src/common/services/UnicodeService.ts b/src/common/services/UnicodeService.ts index b5d19623..239f4d62 100644 --- a/src/common/services/UnicodeService.ts +++ b/src/common/services/UnicodeService.ts @@ -14,7 +14,7 @@ export class UnicodeService implements IUnicodeService { private _active: string = ''; private _activeProvider: IUnicodeVersionProvider; - private _onChange = new EventEmitter(); + private readonly _onChange = new EventEmitter(); public readonly onChange = this._onChange.event; constructor() { diff --git a/src/headless/Terminal.ts b/src/headless/Terminal.ts index 1b1162e5..639988eb 100644 --- a/src/headless/Terminal.ts +++ b/src/headless/Terminal.ts @@ -32,15 +32,15 @@ export class Terminal extends CoreTerminal { // TODO: We should remove options once components adopt optionsService public get options(): Required { return this.optionsService.options; } - private _onBell = new EventEmitter(); + private readonly _onBell = new EventEmitter(); public readonly onBell = this._onBell.event; - private _onCursorMove = new EventEmitter(); + private readonly _onCursorMove = new EventEmitter(); public readonly onCursorMove = this._onCursorMove.event; - private _onTitleChange = new EventEmitter(); + private readonly _onTitleChange = new EventEmitter(); public readonly onTitleChange = this._onTitleChange.event; - private _onA11yCharEmitter = new EventEmitter(); + private readonly _onA11yCharEmitter = new EventEmitter(); public readonly onA11yChar = this._onA11yCharEmitter.event; - private _onA11yTabEmitter = new EventEmitter(); + private readonly _onA11yTabEmitter = new EventEmitter(); public readonly onA11yTab = this._onA11yTabEmitter.event; /**