Skip to content

Commit

Permalink
remove unused selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesribeiro committed Aug 14, 2023
1 parent 9cf319d commit ba41570
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<div *ngIf="playerBoardFromDesktop" class="py-8">
<label>Game info</label>

<div>Flags left: {{ playerBoardFromDesktop.flagsLeft }}</div>
<div>Game status: {{ playerBoardFromDesktop.gameStatus }}</div>
<div>Loaded game status: {{ playerBoardFromDesktop.gameStatus }}</div>
<button
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline float-right"
(click)="proceedWithLoadingState()"
Expand Down
1 change: 0 additions & 1 deletion src/app/models/playerBoard.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { GameStatus } from "./gameStatus.model";

export interface PlayerBoard {
gameStatus: GameStatus;
flagsLeft: number;
entities: Cell[][];
loading: boolean;
error: boolean;
Expand Down
5 changes: 0 additions & 5 deletions src/app/state/app.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ export const setLeftClick = createAction(
props<{ cell: Cell }>(),
);

export const setBoardSize = createAction(
"[Game] set board size action",
props<{ width: number; height: number }>(),
);

export const updateCell = createAction(
"[Game] update cell",
props<{ cell: Cell }>(),
Expand Down
1 change: 0 additions & 1 deletion src/app/state/app.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { IApp } from "./app.interface";
import { TimerService } from "../services/timer.service";
import { RouterTestingModule } from "@angular/router/testing";
import { Router } from "@angular/router";
import { mockSettings } from "../utils/mock-settings";
import { SessionTypes } from "../models/sessionTypes";

describe("AppEffects", () => {
Expand Down
1 change: 0 additions & 1 deletion src/app/state/app.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { PlayerSession } from "../models/session.model";

export interface IApp {
playerBoard: PlayerBoard;
settings: Settings;
playerSession: PlayerSession;
}

Expand Down
12 changes: 0 additions & 12 deletions src/app/state/app.reducer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import * as fromAppActions from "../state/app.actions";
import { Action } from "@ngrx/store";
import { AppReducer, initialAppState, reducer } from "./app.reducer";
import { Level } from "../models/level.model";
import { mockBoard } from "../utils/mock-board";
import { mockCell } from "../utils/mock-cell";
import { GameStatus } from "../models/gameStatus.model";
import { mockSettings } from "../utils/mock-settings";
import { SessionTypes } from "../models/sessionTypes";

describe("appReducer", () => {
Expand All @@ -30,16 +28,6 @@ describe("appReducer", () => {
});
});

describe("setBoardSize", () => {
it("should update the board width and height", () => {
const action = fromAppActions.setBoardSize({ width: 10, height: 20 });
const newState = AppReducer(initialAppState, action);

expect(newState.settings.width).toEqual(10);
expect(newState.settings.height).toEqual(20);
});
});

describe("createMatrixSuccess", () => {
it("should update the realBoard and playerBoard entities", () => {
const action = fromAppActions.createMatrixSuccess({
Expand Down
11 changes: 3 additions & 8 deletions src/app/state/app.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
clickCellFail,
gameOver,
createMatrixSuccess,
setBoardSize,
updateCell,
startGame,
wonGame,
Expand All @@ -25,16 +24,12 @@ export const userFeatureKey = "AppState";

export const initialAppState: IApp = {
playerBoard: playerBoardInitialState,
settings: settingsInitialState,
playerSession: sessionInitialState,
};

export const reducer = createReducer(
initialAppState as IApp,
on(setBoardSize, (state, { width, height }) => ({
...state,
settings: { ...state.settings, width, height },
})),

on(createMatrixSuccess, (state, { entities }) => ({
...state,
playerBoard: {
Expand Down Expand Up @@ -64,7 +59,7 @@ export const reducer = createReducer(
playerBoard: {
...state.playerBoard,
gameStatus: GameStatus.IN_PROGRESS,
flagsLeft: state.settings.totalMines,
flagsLeft: 3,
loading: true,
error: false,
},
Expand All @@ -77,7 +72,7 @@ export const reducer = createReducer(
playerBoard: {
...state.playerBoard,
gameStatus: GameStatus.IN_PROGRESS,
flagsLeft: state.settings.totalMines,
flagsLeft: 3,
loading: true,
error: false,
},
Expand Down
12 changes: 1 addition & 11 deletions src/app/state/app.selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ describe("AppSelectors", () => {
const initialState: IAppState = {
AppState: {
...initialAppState,
settings: mockSettings,
playerBoard: { ...initialAppState.playerBoard, flagsLeft: 8 },
},
Settings: mockSettings,
};
Expand Down Expand Up @@ -61,15 +59,7 @@ describe("AppSelectors", () => {
getAppState(initialState),
);

expect(result).toEqual({ ...initialAppState.playerBoard, flagsLeft: 8 });
});

it("should select total mines", () => {
const result = fromAppSelectors.selectFlagsLeft.projector(
getAppState(initialState),
);

expect(result).toEqual(8);
expect(result).toEqual({ ...initialAppState.playerBoard });
});

it("should select player board without any pristine cells", () => {
Expand Down
8 changes: 4 additions & 4 deletions src/app/state/app.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export const selectGameStatus = createSelector(
selectFeature,
(appState: IApp) => appState?.playerBoard.gameStatus,
);
export const selectFlagsLeft = createSelector(
selectFeature,
(appState: IApp) => appState?.playerBoard.flagsLeft,
);
// export const selectFlagsLeft = createSelector(
// selectFeature,
// (appState: IApp) => appState?.playerBoard.flagsLeft,
// );
export const selectGameLoading = createSelector(
selectFeature,
(appState: IApp) => appState?.playerBoard.loading,
Expand Down
2 changes: 1 addition & 1 deletion src/app/utils/store-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const playerBoardInitialState: PlayerBoard = {
loading: false,
error: false,
gameStatus: GameStatus.NOT_PLAYING,
flagsLeft: Infinity,
// flagsLeft: Infinity,
};

export const settingsInitialState: Settings = {
Expand Down
6 changes: 5 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
<title>Minesweeper</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="assets/images/MINESWEEPER_M.png" />
<link
rel="icon"
type="image/x-icon"
href="assets/images/MINESWEEPER_M.png"
/>
</head>
<body>
<app-root></app-root>
Expand Down

0 comments on commit ba41570

Please sign in to comment.