Archived
1
0

Some cleanup

- Use whateverEmitter.event for the onWhatever methods.
- Add readonly to a bunch of things.
- Remove some redundancy in types.
- Move initializations out of the constructor and into the declarations
  where it was reasonable to do so.
- Disable a few no-any violations.
This commit is contained in:
Asher
2019-02-06 11:53:23 -06:00
parent ddf96077a3
commit 588da0443c
16 changed files with 98 additions and 164 deletions

View File

@ -3,7 +3,7 @@ import { ChildProcess } from "child_process";
export interface IpcMessage {
readonly event: string;
readonly args: any[];
readonly args: any[]; // tslint:disable-line no-any
}
export class StdioIpcHandler extends EventEmitter {
@ -15,21 +15,28 @@ export class StdioIpcHandler extends EventEmitter {
super();
}
// tslint:disable-next-line no-any
public on(event: string, cb: (...args: any[]) => void): this {
this.listen();
return super.on(event, cb);
}
// tslint:disable-next-line no-any
public once(event: string, cb: (...args: any[]) => void): this {
this.listen();
return super.once(event, cb);
}
// tslint:disable-next-line no-any
public addListener(event: string, cb: (...args: any[]) => void): this {
this.listen();
return super.addListener(event, cb);
}
// tslint:disable-next-line no-any
public send(event: string, ...args: any[]): void {
const msg: IpcMessage = {
event,
@ -47,7 +54,8 @@ export class StdioIpcHandler extends EventEmitter {
if (this.isListening) {
return;
}
const onData = (data: any) => {
// tslint:disable-next-line no-any
const onData = (data: any): void => {
try {
const d = JSON.parse(data.toString()) as IpcMessage;
this.emit(d.event, ...d.args);

View File

@ -26,20 +26,16 @@ export class SharedProcess {
private _state: SharedProcessState = SharedProcessState.Stopped;
private activeProcess: ChildProcess | undefined;
private ipcHandler: StdioIpcHandler | undefined;
private readonly onStateEmitter: Emitter<SharedProcessEvent>;
private readonly onStateEmitter = new Emitter<SharedProcessEvent>();
public readonly onState = this.onStateEmitter.event;
public constructor(
private readonly userDataDir: string,
private readonly builtInExtensionsDir: string,
) {
this.onStateEmitter = new Emitter();
this.restart();
}
public get onState(): Event<SharedProcessEvent> {
return this.onStateEmitter.event;
}
public get state(): SharedProcessState {
return this._state;
}