Skip to content

Commit

Permalink
fix(client): Better represent data composition in React client types
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis committed Sep 13, 2020
1 parent e578cb3 commit e5ab5f0
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/client/react.tsx
Expand Up @@ -9,7 +9,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Client as RawClient, ClientOpts, _ClientImpl } from './client';
import { State, Ctx } from '../types';

type WrappedBoardDelegates = 'matchID' | 'playerID' | 'credentials';

Expand All @@ -18,26 +17,24 @@ export type WrappedBoardProps = Pick<
WrappedBoardDelegates | 'debug'
>;

export type BoardProps<
G extends any = any,
CtxWithPlugins extends Ctx = Ctx
> = State<G, CtxWithPlugins> &
Pick<
_ClientImpl<G>,
| 'log'
| 'moves'
| 'events'
| 'reset'
| 'undo'
| 'redo'
| 'playerID'
| 'matchID'
| 'matchData'
| 'credentials'
> & {
isActive: boolean;
type ClientState<G extends any = any> = ReturnType<_ClientImpl<G>['getState']>;
type ExposedClientProps<G extends any = any> = Pick<
_ClientImpl<G>,
| 'log'
| 'moves'
| 'events'
| 'reset'
| 'undo'
| 'redo'
| 'playerID'
| 'matchID'
| 'matchData'
>;

export type BoardProps<G extends any = any> = ClientState<G> &
Omit<WrappedBoardProps, keyof ExposedClientProps<G>> &
ExposedClientProps<G> & {
isMultiplayer: boolean;
isConnected: boolean;
};

type ReactClientOpts<
Expand Down

0 comments on commit e5ab5f0

Please sign in to comment.