Adopt DI in browser services

This commit is contained in:
Daniel Imms
2019-07-13 22:26:13 -07:00
parent 5cc8ad802c
commit 88c88f1141
8 changed files with 55 additions and 23 deletions
+2
View File
@@ -7,6 +7,7 @@ import { IEvent, EventEmitter } from 'common/EventEmitter';
import { ICharSizeService, IMouseService } from 'browser/services/Services';
export class MockCharSizeService implements ICharSizeService {
_serviceBrand: any;
get hasValidSize(): boolean { return this.width > 0 && this.height > 0; }
onCharSizeChange: IEvent<void> = new EventEmitter<void>().event;
constructor(public width: number, public height: number) {}
@@ -14,6 +15,7 @@ export class MockCharSizeService implements ICharSizeService {
}
export class MockMouseService implements IMouseService {
_serviceBrand: any;
public getCoords(event: {clientX: number, clientY: number}, element: HTMLElement, colCount: number, rowCount: number, isSelection?: boolean): [number, number] | undefined {
throw new Error('Not implemented');
}
+5 -3
View File
@@ -8,6 +8,8 @@ import { IEvent, EventEmitter } from 'common/EventEmitter';
import { ICharSizeService } from 'browser/services/Services';
export class CharSizeService implements ICharSizeService {
_serviceBrand: any;
public width: number = 0;
public height: number = 0;
private _measureStrategy: IMeasureStrategy;
@@ -18,9 +20,9 @@ export class CharSizeService implements ICharSizeService {
public get onCharSizeChange(): IEvent<void> { return this._onCharSizeChange.event; }
constructor(
document: Document,
parentElement: HTMLElement,
private _optionsService: IOptionsService
readonly document: Document,
readonly parentElement: HTMLElement,
@IOptionsService private readonly _optionsService: IOptionsService
) {
this._measureStrategy = new DomMeasureStrategy(document, parentElement, this._optionsService);
}
+4 -2
View File
@@ -7,9 +7,11 @@ import { ICharSizeService, IRenderService, IMouseService } from './Services';
import { getCoords, getRawByteCoords } from 'browser/input/Mouse';
export class MouseService implements IMouseService {
_serviceBrand: any;
constructor(
private readonly _renderService: IRenderService,
private readonly _charSizeService: ICharSizeService
@IRenderService private readonly _renderService: IRenderService,
@ICharSizeService private readonly _charSizeService: ICharSizeService
) {
}
+5 -3
View File
@@ -14,6 +14,8 @@ import { IOptionsService } from 'common/services/Services';
import { ICharSizeService, IRenderService } from 'browser/services/Services';
export class RenderService extends Disposable implements IRenderService {
_serviceBrand: any;
private _renderDebouncer: RenderDebouncer;
private _screenDprMonitor: ScreenDprMonitor;
@@ -34,9 +36,9 @@ export class RenderService extends Disposable implements IRenderService {
constructor(
private _renderer: IRenderer,
private _rowCount: number,
screenElement: HTMLElement,
optionsService: IOptionsService,
charSizeService: ICharSizeService
readonly screenElement: HTMLElement,
@IOptionsService readonly optionsService: IOptionsService,
@ICharSizeService readonly charSizeService: ICharSizeService
) {
super();
this._renderDebouncer = new RenderDebouncer((start, end) => this._renderRows(start, end));
+7 -5
View File
@@ -67,6 +67,8 @@ export const enum SelectionMode {
* when the selection is ready to be redrawn (on an animation frame).
*/
export class SelectionService implements ISelectionService {
_serviceBrand: any;
protected _model: SelectionModel;
/**
@@ -114,11 +116,11 @@ export class SelectionService implements ISelectionService {
private readonly _scrollLines: (amount: number, suppressEvent: boolean) => void,
private readonly _element: HTMLElement,
private readonly _screenElement: HTMLElement,
private readonly _charSizeService: ICharSizeService,
private readonly _bufferService: IBufferService,
private readonly _coreService: ICoreService,
private readonly _mouseService: IMouseService,
private readonly _optionsService: IOptionsService
@ICharSizeService private readonly _charSizeService: ICharSizeService,
@IBufferService private readonly _bufferService: IBufferService,
@ICoreService private readonly _coreService: ICoreService,
@IMouseService private readonly _mouseService: IMouseService,
@IOptionsService private readonly _optionsService: IOptionsService
) {
// Init listeners
this._mouseMoveListener = event => this._onMouseMove(<MouseEvent>event);
@@ -7,8 +7,12 @@ import { IEvent } from 'common/EventEmitter';
import { IRenderDimensions, IRenderer, CharacterJoinerHandler } from 'browser/renderer/Types';
import { IColorSet } from 'browser/Types';
import { ISelectionRedrawRequestEvent } from 'browser/selection/Types';
import { createDecorator } from 'common/services/ServiceRegistry';
export const ICharSizeService = createDecorator<ICharSizeService>('CharSizeService');
export interface ICharSizeService {
_serviceBrand: any;
readonly width: number;
readonly height: number;
readonly hasValidSize: boolean;
@@ -18,12 +22,18 @@ export interface ICharSizeService {
measure(): void;
}
export const IMouseService = createDecorator<IMouseService>('MouseService');
export interface IMouseService {
_serviceBrand: any;
getCoords(event: {clientX: number, clientY: number}, element: HTMLElement, colCount: number, rowCount: number, isSelection?: boolean): [number, number] | undefined;
getRawByteCoords(event: MouseEvent, element: HTMLElement, colCount: number, rowCount: number): { x: number, y: number } | undefined;
}
export const IRenderService = createDecorator<IRenderService>('RenderService');
export interface IRenderService {
_serviceBrand: any;
onDimensionsChange: IEvent<IRenderDimensions>;
onRender: IEvent<{ start: number, end: number }>;
onRefreshRequest: IEvent<{ start: number, end: number }>;
@@ -48,7 +58,10 @@ export interface IRenderService {
deregisterCharacterJoiner(joinerId: number): boolean;
}
export const ISelectionService = createDecorator<ISelectionService>('SelectionService');
export interface ISelectionService {
_serviceBrand: any;
readonly selectionText: string;
readonly hasSelection: boolean;
readonly selectionStart: [number, number] | undefined;
@@ -73,6 +86,9 @@ export interface ISelectionService {
onMouseDown(event: MouseEvent): void;
}
export const ISoundService = createDecorator<ISoundService>('SoundService');
export interface ISoundService {
_serviceBrand: any;
playBellSound(): void;
}
+3 -1
View File
@@ -7,6 +7,8 @@ import { IOptionsService } from 'common/services/Services';
import { ISoundService } from 'browser/services/Services';
export class SoundService implements ISoundService {
_serviceBrand: any;
private static _audioContext: AudioContext;
static get audioContext(): AudioContext | null {
@@ -22,7 +24,7 @@ export class SoundService implements ISoundService {
}
constructor(
private _optionsService: IOptionsService
@IOptionsService private _optionsService: IOptionsService
) {
}