Skip to content

Commit b329df2

Browse files
jstacodernicolodavis
authored andcommitted
Pass through props (#173)
* added props to client config * updated to passing props by rest/spread
1 parent e041af1 commit b329df2

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/client/react.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,32 @@ export function Client({
100100
let _debug = null;
101101

102102
const state = this.client.getState();
103+
const { gameID, playerID, debug: debugProp, ...rest } = this.props;
103104

104105
if (board) {
105106
_board = React.createElement(board, {
106107
...state,
107108
isMultiplayer: multiplayer !== undefined,
108109
moves: this.client.moves,
109110
events: this.client.events,
110-
gameID: this.props.gameID,
111-
playerID: this.props.playerID,
111+
gameID: gameID,
112+
playerID: playerID,
112113
reset: this.client.reset,
113114
undo: this.client.undo,
114115
redo: this.client.redo,
116+
...rest,
115117
});
116118
}
117119

118-
if (debug && this.props.debug) {
120+
if (debug && debugProp) {
119121
_debug = React.createElement(Debug, {
120122
gamestate: state,
121123
store: this.client.store,
122124
isMultiplayer: multiplayer !== undefined,
123125
moves: this.client.moves,
124126
events: this.client.events,
125-
gameID: this.props.gameID,
126-
playerID: this.props.playerID,
127+
gameID: gameID,
128+
playerID: playerID,
127129
reset: this.client.reset,
128130
undo: this.client.undo,
129131
redo: this.client.redo,

src/client/react.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ test('board props', () => {
7777
expect(board.props().isActive).toBe(true);
7878
});
7979

80+
test('can pass extra props to Client', () => {
81+
const Board = Client({
82+
game: Game({}),
83+
board: TestBoard,
84+
});
85+
const board = Enzyme.mount(
86+
<Board doStuff={() => true} extraValue={55} />
87+
).find(TestBoard);
88+
expect(board.props().doStuff()).toBe(true);
89+
expect(board.props().extraValue).toBe(55);
90+
});
91+
8092
test('debug ui can be turned off', () => {
8193
const Board = Client({
8294
game: Game({}),

0 commit comments

Comments
 (0)