applyFilters()
Applies all selected filters from the UI to the Pokémon list.Behavior
- Reads values from all filter elements (type, generation, color, habitat, size, weight)
- Validates that the selected type exists in available types
- Shows loading indicator during filter application
- Ensures necessary Pokémon data is loaded for generation and type filters
- Applies all criteria using
_applyPokemonFilters() - Resets pagination to page 1
- Updates display and pagination
- Handles errors gracefully
Filter Criteria
Pokémon type (normal, fire, water, electric, grass, etc.)
Generation number (1-9)
Pokémon color (black, blue, brown, gray, green, pink, purple, red, white, yellow)
Pokémon habitat (cave, forest, grassland, mountain, rare, rough-terrain, sea, urban, waters-edge)
Size category based on height
Weight category
Example
_applyPokemonFilters()
Internal method that filters a Pokémon list based on multiple criteria.Array of Pokémon objects to filter
Object containing filter criteria:
name: string - Filter by name (partial match)type: string - Filter by typecolor: string - Filter by colorhabitat: string - Filter by habitatgeneration: string - Filter by generation numbersize: string - Filter by size categoryweight: string - Filter by weight category
Filtered array of Pokémon objects matching all criteria
Size Categories
- tiny: Height < 0.5m
- small: Height 0.5m - 1m
- medium: Height 1m - 2m
- large: Height 2m - 3m
- huge: Height >= 3m
Weight Categories
- light: Weight < 10kg
- normal: Weight 10kg - 50kg
- heavy: Weight 50kg - 100kg
- massive: Weight >= 100kg
Example
loadPokemonByType()
Loads all Pokémon of a specific type from the API if not already cached.The Pokémon type to load (fire, water, grass, etc.)
Behavior
- Checks if enough Pokémon of the requested type are already loaded (threshold: 10)
- If not, fetches complete list from PokéAPI’s type endpoint
- Filters results to only include Pokémon with ID less than or equal to 1025
- Loads missing Pokémon details using
loadMissingPokemon() - Updates internal caches (
pokemonById,pokemonByName,allPokemon)
Example
This method optimizes performance by only fetching data when the cache is insufficient.
ensureGenerationLoaded()
Ensures all Pokémon from a specific generation are loaded into memory.Generation number (“1” through “9”)
Generation Ranges
View Generation Ranges
View Generation Ranges
- Generation 1: ID 1-151 (Kanto)
- Generation 2: ID 152-251 (Johto)
- Generation 3: ID 252-386 (Hoenn)
- Generation 4: ID 387-493 (Sinnoh)
- Generation 5: ID 494-649 (Unova)
- Generation 6: ID 650-721 (Kalos)
- Generation 7: ID 722-809 (Alola)
- Generation 8: ID 810-905 (Galar)
- Generation 9: ID 906-1025 (Paldea)
Behavior
- Validates generation number exists in constants
- Calculates ID range for the generation
- Identifies which Pokémon IDs are not yet cached
- Loads missing Pokémon using
loadMissingPokemon() - Returns immediately if all Pokémon are already loaded