41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { Reducer } from 'redux';
|
|
|
|
import * as Actions from './actions';
|
|
import { IPokemonSelectListState, PokemonSelectListActionTypes } from './types';
|
|
|
|
export const initialState : IPokemonSelectListState = {
|
|
activePokemonIndex: -1,
|
|
pokemonList: [],
|
|
pokemonListFiltered: [],
|
|
};
|
|
|
|
const reduceSetPokemonList = (
|
|
state : IPokemonSelectListState,
|
|
action : ReturnType<typeof Actions.setPokemonList>
|
|
) : IPokemonSelectListState => ({
|
|
...state,
|
|
pokemonList: action.payload.pokemonList,
|
|
});
|
|
|
|
const reduceSetActivePokemonIndex = (
|
|
state : IPokemonSelectListState,
|
|
action : ReturnType<typeof Actions.setActivePokemonIndex>
|
|
) : IPokemonSelectListState => ({
|
|
...state,
|
|
activePokemonIndex: action.payload.activePokemonIndex,
|
|
});
|
|
|
|
export const PokemonSelectListReducers : Reducer<IPokemonSelectListState> = (
|
|
state : IPokemonSelectListState = initialState,
|
|
action,
|
|
) : IPokemonSelectListState => {
|
|
switch (action.type) {
|
|
case PokemonSelectListActionTypes.SET_POKEMON_LIST:
|
|
return reduceSetPokemonList(state, action as ReturnType<typeof Actions.setPokemonList>);
|
|
case PokemonSelectListActionTypes.SET_ACTIVE_POKEMON_INDEX:
|
|
return reduceSetActivePokemonIndex(state, action as ReturnType<typeof Actions.setActivePokemonIndex>);
|
|
default:
|
|
return state;
|
|
}
|
|
};
|