Skip to content

Commit

Permalink
fix config merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Hendrik Helms committed May 13, 2023
1 parent ee1e400 commit 8d4c24b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ Example Typescript Component
import { ref } from 'vue';
import { TheChessboard } from 'vue3-chessboard';
import 'vue3-chessboard/style.css';
import type { ChessboardAPI, BoardConfig } from 'vue3-chessboard';
import type { BoardApi, BoardConfig } from 'vue3-chessboard';
const boardAPI = ref<ChessboardAPI>();
const boardAPI = ref<BoardApi>();
const boardConfig: BoardConfig = {
coordinates: false,
autoCastle: false,
Expand Down
2 changes: 1 addition & 1 deletion src/classes/BoardApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export class BoardApi {
/**
* apply the fen game on the board
*/
updateGameState(): void {
private updateGameState(): void {
this.board.set({ fen: this.game.fen() });
this.board.state.turnColor = shortToLongColor(this.game.turn());
this.board.state.movable.color = this.board.state.turnColor;
Expand Down
6 changes: 2 additions & 4 deletions src/components/TheChessboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getThreats,
isPromotion,
shortToLongColor,
merge,
} from '@/helper/Board';
import { defaultBoardConfig } from '@/helper/DefaultConfig';
import { emitBoardEvents } from '@/helper/EmitEvents';
Expand Down Expand Up @@ -59,10 +60,7 @@ onMounted(() => {
}
if (props.boardConfig) {
boardState.value.boardConfig = {
...defaultBoardConfig,
...props.boardConfig,
};
boardState.value.boardConfig = merge(defaultBoardConfig, props.boardConfig);
} else {
boardState.value.boardConfig = defaultBoardConfig;
}
Expand Down
11 changes: 11 additions & 0 deletions src/helper/Board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,14 @@ export function isPromotion(dest: Key, piece: Piece | null): boolean {
export function getPossiblePromotions(legalMoves: Move[]): Move[] {
return legalMoves.filter((move) => move.promotion);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function merge(target: any, source: any): any {
for (const key of Object.keys(source)) {
if (source[key] instanceof Object)
Object.assign(source[key], merge(target[key], source[key]));
}

Object.assign(target || {}, source);
return target;
}

0 comments on commit 8d4c24b

Please sign in to comment.