Skip to content

Commit

Permalink
Fix type emitting for some types
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed May 13, 2020
1 parent b3c05cd commit eabda5f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
10 changes: 6 additions & 4 deletions src/devices/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type DeviceEvents = {
announced: (device: Device) => void;
};

type Emitter = StrictEventEmitter<EventEmitter, DeviceEvents>;

/**
* The device manager is responsible for tracking devices that appear on the
* prolink network, providing an API to react to devices livecycle events as
Expand All @@ -66,7 +68,7 @@ class DeviceManager {
/**
* The EventEmitter which will be used to trigger device lifecycle events
*/
#emitter: StrictEventEmitter<EventEmitter, DeviceEvents> = new EventEmitter();
#emitter: Emitter = new EventEmitter();

constructor(announceSocket: SocketAsPromised, config?: Config) {
this.#config = {...defaultConfig, ...config};
Expand All @@ -76,9 +78,9 @@ class DeviceManager {
}

// Bind public event emitter interface
on = this.#emitter.addListener.bind(this.#emitter);
off = this.#emitter.removeListener.bind(this.#emitter);
once = this.#emitter.once.bind(this.#emitter);
on: Emitter['on'] = this.#emitter.addListener.bind(this.#emitter);
off: Emitter['off'] = this.#emitter.removeListener.bind(this.#emitter);
once: Emitter['once'] = this.#emitter.once.bind(this.#emitter);

/**
* Get active devices on the network.
Expand Down
12 changes: 7 additions & 5 deletions src/localdb/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {createHash} from 'crypto';
import {Connection, createConnection} from 'typeorm';
import {createHash} from 'crypto';
import {EventEmitter} from 'events';
import {Mutex} from 'async-mutex';
import StrictEventEmitter from 'strict-event-emitter-types';
Expand Down Expand Up @@ -64,6 +64,8 @@ type DatabaseEvents = {
hydrationProgress: (opts: HydrationPrgoressOpts) => void;
};

type Emitter = StrictEventEmitter<EventEmitter, DatabaseEvents>;

type DatabaseItem = {
/**
* The uniquity identifier of the database
Expand Down Expand Up @@ -122,7 +124,7 @@ class LocalDatabase {
/**
* The EventEmitter that will report database events
*/
#emitter: StrictEventEmitter<EventEmitter, DatabaseEvents> = new EventEmitter();
#emitter: Emitter = new EventEmitter();
/**
* Locks for each device slot: ${device.id}-${slot}. Used when making track
* requets.
Expand All @@ -146,9 +148,9 @@ class LocalDatabase {
}

// Bind public event emitter interface
on = this.#emitter.addListener.bind(this.#emitter);
off = this.#emitter.removeListener.bind(this.#emitter);
once = this.#emitter.once.bind(this.#emitter);
on: Emitter['on'] = this.#emitter.addListener.bind(this.#emitter);
off: Emitter['off'] = this.#emitter.removeListener.bind(this.#emitter);
once: Emitter['once'] = this.#emitter.once.bind(this.#emitter);

/**
* Closes the database connection and removes the database entry when a
Expand Down
10 changes: 6 additions & 4 deletions src/mixstaus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type MixstatusEvents = {
setEnded: () => void;
};

type Emitter = StrictEventEmitter<EventEmitter, MixstatusEvents>;

/**
* MixstatusProcessor is a configurable processor which when fed device state
* will attempt to accurately determine events that happen within the DJ set.
Expand Down Expand Up @@ -113,7 +115,7 @@ class MixstatusProcessor {
/**
* Used to fire track mix status events
*/
#emitter: StrictEventEmitter<EventEmitter, MixstatusEvents> = new EventEmitter();
#emitter: Emitter = new EventEmitter();
/**
* Records the most recent state of each player
*/
Expand Down Expand Up @@ -149,9 +151,9 @@ class MixstatusProcessor {
}

// Bind public event emitter interface
on = this.#emitter.addListener.bind(this.#emitter);
off = this.#emitter.removeListener.bind(this.#emitter);
once = this.#emitter.once.bind(this.#emitter);
on: Emitter['on'] = this.#emitter.addListener.bind(this.#emitter);
off: Emitter['off'] = this.#emitter.removeListener.bind(this.#emitter);
once: Emitter['once'] = this.#emitter.once.bind(this.#emitter);

/**
* Report a player as 'live'. Will not report the state if the player has
Expand Down
4 changes: 2 additions & 2 deletions src/remotedb/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export enum FieldType {
/**
* The generic interface for all field types
*/
interface BaseField {
export interface BaseField {
/**
* The raw field data
*/
Expand All @@ -28,7 +28,7 @@ interface BaseField {
readonly buffer: Buffer;
}

class BaseField {
export class BaseField {
/**
* Declares the type of field this class represents
*/
Expand Down
2 changes: 1 addition & 1 deletion src/remotedb/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Message} from './message';
import {UInt32, Binary} from './fields';

/**
* This module contains logic for each type of query to udnerstand what
* This module contains logic for each type of query to understand what
* arguments are required, and how to transform the resulting Items into
* something useful.
*/
Expand Down
10 changes: 6 additions & 4 deletions src/status/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type StatusEvents = {
mediaSlot: (info: MediaSlotInfo) => void;
};

type Emitter = StrictEventEmitter<EventEmitter, StatusEvents>;

type MediaSlotOptions = Parameters<typeof makeMediaSlotRequest>[0];

/**
Expand All @@ -30,7 +32,7 @@ class StatusEmitter {
/**
* The EventEmitter which reports the device status
*/
#emitter: StrictEventEmitter<EventEmitter, StatusEvents> = new EventEmitter();
#emitter: Emitter = new EventEmitter();
/**
* Lock used to avoid media slot query races
*/
Expand All @@ -45,9 +47,9 @@ class StatusEmitter {
}

// Bind public event emitter interface
on = this.#emitter.addListener.bind(this.#emitter);
off = this.#emitter.removeListener.bind(this.#emitter);
once = this.#emitter.once.bind(this.#emitter);
on: Emitter['on'] = this.#emitter.addListener.bind(this.#emitter);
off: Emitter['off'] = this.#emitter.removeListener.bind(this.#emitter);
once: Emitter['once'] = this.#emitter.once.bind(this.#emitter);

#handleStatus = (message: Buffer) => {
const status = statusFromPacket(message);
Expand Down

0 comments on commit eabda5f

Please sign in to comment.