Skip to content

Commit

Permalink
refactor(client): Structure debug types to output a .d.ts file
Browse files Browse the repository at this point in the history
This places the Svelte Debug component type definition in an index.ts 
alongside the index.js that re-exports the Svelte component.
  • Loading branch information
delucis committed Jun 26, 2020
1 parent ac91454 commit e8f0735
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,9 @@ import {
type ClientAction = ActionShape.Reset | ActionShape.Sync | ActionShape.Update;
type Action = CredentialedActionShape.Any | ClientAction;

// TODO: Replace these types with the full debug interface.
// These types only specify the known interface used by a client instance.
declare class DebugPanel {
constructor(opts: { target: HTMLElement; props: { client: _ClientImpl } });
$destroy: () => void;
}
type Debug = {
type DebugOpts = {
target?: HTMLElement;
impl?: typeof DebugPanel;
impl?: typeof Debug;
};

/**
Expand Down Expand Up @@ -93,7 +87,7 @@ export const createPluginDispatchers = createDispatchers.bind(null, 'plugin');

export interface ClientOpts<G extends any = any> {
game: Game<G>;
debug?: Debug | boolean;
debug?: DebugOpts | boolean;
numPlayers?: number;
multiplayer?: (opts: TransportOpts) => Transport;
gameID?: string;
Expand All @@ -106,8 +100,8 @@ export interface ClientOpts<G extends any = any> {
* Implementation of Client (see below).
*/
export class _ClientImpl<G extends any = any> {
private debug?: Debug | boolean;
private _debugPanel?: DebugPanel | null;
private debug?: DebugOpts | boolean;
private _debugPanel?: Debug | null;
private gameStateOverride?: any;
private initialState: State<G>;
private multiplayer: (opts: TransportOpts) => Transport;
Expand Down Expand Up @@ -329,7 +323,7 @@ export class _ClientImpl<G extends any = any> {
this.transport.connect();
this._running = true;

let debugImpl: Debug['impl'] | null = null;
let debugImpl: typeof Debug | null = null;

if (process.env.NODE_ENV !== 'production') {
debugImpl = Debug;
Expand Down
8 changes: 8 additions & 0 deletions src/client/debug/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { _ClientImpl } from '../client';

declare class Debug {
constructor(opts: { target: HTMLElement; props: { client: _ClientImpl } });
$destroy: () => void;
}

export default Debug;

0 comments on commit e8f0735

Please sign in to comment.