Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix client types & move BoardProps to React package #752

Merged
merged 12 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
"style-loader": "^0.18.2",
"superagent": "^3.8.3",
"supertest": "^3.1.0",
"svelte": "^3.12.1",
"svelte-icons": "^1.1.0",
"tempy": "^0.5.0",
"ts-jest": "^24.0.2",
Expand All @@ -161,6 +160,7 @@
"redux": "^4.0.0",
"shortid": "^2.2.14",
"socket.io": "^2.1.1",
"svelte": "^3.24.0",
"ts-toolbelt": "^6.3.6",
"uuid": "3.2.1"
},
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions packages/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* https://opensource.org/licenses/MIT.
*/

import { Client } from '../src/client/react';
import { Client, BoardProps } from '../src/client/react';
import Lobby from '../src/lobby/react';

export { Client, Lobby };
export { Client, BoardProps, Lobby };
6 changes: 0 additions & 6 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ export default [
{
input: subpackages.reduce((obj, name) => {
obj[name] = `packages/${name}.ts`;

// The debug package can't be converted to TS
// yet due to the svelte import.
if (name == 'debug') {
obj[name] = 'packages/debug.js';
}
return obj;
}, {}),
external,
Expand Down
2 changes: 1 addition & 1 deletion src/client/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Transport } from './transport/transport';
import { LocalTransport, Local } from './transport/local';
import { SocketIOTransport, SocketIO } from './transport/socketio';
import { update, sync, makeMove, gameEvent } from '../core/action-creators';
import Debug from './debug';
import Debug from './debug/Debug.svelte';
import { error } from '../core/logger';
import { LogEntry, State, SyncInfo } from '../types';

Expand Down
22 changes: 8 additions & 14 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import * as Actions from '../core/action-types';
import * as ActionCreators from '../core/action-creators';
import { ProcessGameConfig } from '../core/game';
import Debug from './debug';
import Debug from './debug/Debug.svelte';
import { CreateGameReducer } from '../core/reducer';
import { InitializeGame } from '../core/initialize';
import { Transport, TransportOpts } from './transport/transport';
Expand All @@ -35,16 +35,10 @@ 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 = {
interface DebugOpt {
target?: HTMLElement;
impl?: typeof DebugPanel;
};
impl?: typeof Debug;
}

/**
* createDispatchers
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?: DebugOpt | 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?: DebugOpt | 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: DebugOpt['impl'] | null = null;

if (process.env.NODE_ENV !== 'production') {
debugImpl = Debug;
Expand Down
2 changes: 0 additions & 2 deletions src/client/debug/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Object } from 'ts-toolbelt';
import Koa from 'koa';
import { Store as ReduxStore } from 'redux';
import 'svelte';
import * as ActionCreators from './core/action-creators';
import { Flow } from './core/flow';
import { CreateGameReducer } from './core/reducer';
Expand All @@ -10,7 +11,6 @@ import { EventsAPI } from './plugins/plugin-events';
import { RandomAPI } from './plugins/plugin-random';

export { StorageAPI };
export { BoardProps } from './client/react';

export type AnyFn = (...args: any[]) => any;

Expand Down