Overview
ThePokemonExplorer class is the core of the Pokémon Explorer application. It handles data fetching, search, filtering, pagination, and UI rendering for browsing over 1,300 Pokémon.
Constructor
- API configuration
- Translation constants
- State management
- DOM element references
- Event listeners
- Initial data loading
Properties
API Configuration
Base URL for the PokéAPI endpoints
Constants
Configuration object containing translation maps and settings
State Properties
Current pagination page number
Number of Pokémon displayed per page
Complete list of loaded Pokémon objects
Pokémon list after applying search/filters
Fast lookup map for Pokémon by ID
Fast lookup map for Pokémon by name
Whether user has activated audio playback
DOM Elements
References to key DOM elements
Core Methods
Data Loading
loadInitialData()
loadInitialData()
- Pokémon types
- Color options
- Habitat options
- Populates filter dropdowns
- Triggers initial Pokémon load
Promise<void>loadPokemon()
loadPokemon()
Promise<void>loadMissingPokemon(list, key)
loadMissingPokemon(list, key)
list(Array): List of Pokémon IDs or names to loadkey(string): Either'id'or'name'to specify lookup type
Promise<void>fetchPokemonDetails(idOrName)
fetchPokemonDetails(idOrName)
idOrName(number | string): Pokémon ID or name
Promise<Pokemon | null> - Pokémon object or null if not foundPokemon object structure:Search & Filtering
handleSearch(query)
handleSearch(query)
query(string): Search input value
voidparseSmartSearch(query)
parseSmartSearch(query)
query(string): Raw search query (e.g., “planta verde pequeño”)
object - Parsed criteria:performSearch(query)
performSearch(query)
query(string): Search query
Promise<void>applyFilters()
applyFilters()
Promise<void>Display & UI
displayPokemon()
displayPokemon()
voidcreatePokemonCard(pokemon)
createPokemonCard(pokemon)
- Image with loading states
- Name and ID
- Type badges
- Expandable details (stats, abilities, physical attributes)
- Audio cry button (if available)
pokemon(Pokemon): Pokémon object
HTMLElement - The card elementupdatePagination()
updatePagination()
voidpopulateFilters()
populateFilters()
voidUtility Methods
translate(key, translationMap, fallbackFormatter)
translate(key, translationMap, fallbackFormatter)
key(string): Key to translatetranslationMap(string): Name of the translation map (e.g., ‘typeTranslations’)fallbackFormatter(function | null): Optional formatter for untranslated keys
string - Translated valueplayPokemonCry(cryUrl, button)
playPokemonCry(cryUrl, button)
resetAllFilters()
resetAllFilters()
voidclearAllFilters()
clearAllFilters()
voidshowLoading(show, message)
showLoading(show, message)
show(boolean): Whether to show the indicatormessage(string): Loading message text
voidshowError(message) / clearError()
showError(message) / clearError()
message(string): Error message to display
voidUsage Example
Events
The class automatically sets up event listeners for:- Search input (with debouncing)
- All filter dropdowns
- Focus/blur on search field
- Click outside to close suggestions
Performance
- Lazy loading: Pokémon details are only fetched when needed
- Batch processing: Multiple API calls are grouped (50 per batch)
- Caching: All fetched Pokémon are cached in memory (Map structures)
- Debouncing: Search queries are debounced by 300ms
- Pagination: Only renders 12 Pokémon per page
See Also
- PokemonTour - Interactive tour guide class
- Search Guide - How to use smart search features
- Filtering Guide - Advanced filtering options