Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 4x 4x 4x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 5x 4x 9x | import { createSlice } from "@reduxjs/toolkit"
import type { PayloadAction } from "@reduxjs/toolkit"
import { IGame } from "../pages/api/lib/interfaces/IGame"
const initialState: IGame = {
id: "",
name: "",
tags: [],
provider: "",
gameType: "",
}
export const gameSlice = createSlice({
name: "gameSlice",
initialState,
reducers: {
// Redux Toolkit allows us to write "mutating" logic in reducers. It
// doesn't actually mutate the state because it uses the Immer library,
// which detects changes to a "draft state" and produces a brand new
// immutable state based off those changes
saveGame: (game, action: PayloadAction<IGame>) => {
const { id, name, tags, provider, gameType } = action.payload
game.id = id
game.name = name
game.tags = tags
game.provider = provider
game.gameType = gameType
},
removeGame: (game) => {
game.id = ""
game.name = ""
game.tags = []
game.provider = ""
game.gameType = ""
},
},
})
// Export Game Actions
export const { saveGame, removeGame } = gameSlice.actions
// Exports Game Reducer
const gamesReducer = gameSlice.reducer
export default gamesReducer
|