Skip to content

Commit

Permalink
feat(typings): add node type parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Nelson committed Oct 20, 2019
1 parent ea3fe5b commit 3c3dbe5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/base/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default abstract class BaseNode extends EventEmitter {
public shardCount?: number;

public connection?: Connection;
public players: PlayerStore = new PlayerStore(this);
public players: PlayerStore<this> = new PlayerStore(this);
public http?: Http;

public voiceStates: Map<string, string> = new Map();
Expand Down
8 changes: 4 additions & 4 deletions src/core/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export interface Options extends WebSocket.ClientOptions {
resumeTimeout?: number;
}

export default class Connection {
public readonly node: Node;
export default class Connection<T extends Node = Node> {
public readonly node: T;
public url: string;
public options: Options;
public resumeKey?: string;
Expand Down Expand Up @@ -68,8 +68,8 @@ export default class Connection {

private _queue: Array<Sendable> = [];

constructor(client: Node, url: string, options: Options = {}) {
this.node = client;
constructor(node: T, url: string, options: Options = {}) {
this.node = node;
this.url = url;
this.options = options;
this.resumeKey = options.resumeKey;
Expand Down
6 changes: 3 additions & 3 deletions src/core/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export interface JoinOptions {
deaf?: boolean;
}

export default class Player extends EventEmitter {
public readonly node: Node;
export default class Player<T extends Node = Node> extends EventEmitter {
public readonly node: T;
public guildID: string;
public status: Status = Status.INSTANTIATED;

constructor(node: Node, guildID: string) {
constructor(node: T, guildID: string) {
super();
this.node = node;
this.guildID = guildID;
Expand Down
8 changes: 4 additions & 4 deletions src/core/PlayerStore.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Player from './Player';
import Node from '../base/Node';

export default class PlayerStore extends Map<string, Player> {
public readonly node: Node;
export default class PlayerStore<T extends Node = Node> extends Map<string, Player<T>> {
public readonly node: T;

constructor(node: Node) {
constructor(node: T) {
super();
this.node = node;
}

public get(key: string): Player {
public get(key: string): Player<T> {
let player = super.get(key);
if (!player) {
player = new Player(this.node, key);
Expand Down

0 comments on commit 3c3dbe5

Please sign in to comment.