feat(pokemon): debounce async validator and reset validating state in finalize #180
+21
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
The register form’s async Pokémon validator currently issues a network request on each keystroke and toggles the validating spinner accordingly.
Motivation / Problem Statement
Rapid typing triggers multiple unnecessary API calls, keeps the validating spinner active and causes visible flicker as validation rapidly starts/stops. Debouncing prevents redundant requests and avoids unnecessary validation cycles and spinner flicker during continuous typing.
Solution Overview
timer
+switchMap
so the request is sent only after typing pauses.isPokemonValidating
reset intofinalize
so it runs after both success and error paths (single, consistent state flip).pokemonId = -1
when the input is empty to reflect the absence of a selected Pokémon and avoid superfluous requests.pokemonName
updates unchanged aside from the debounce flow.catchError(() => of({ pokemonName: true }))
, ensuring the validator always returns a value (eithernull
or an error object) even when the request fails.Scope of Change
File changed:
src/app/core/validators/pokemon.validator.ts
only.No changes to component templates, routes, or backend APIs.
User-Visible Behavior
isPokemonValidating
) is set once per validation attempt and reset after completion, no rapid on/off toggles during typing.pokemonId = -1
).Testing Instructions
Run: npm i && npm start
pika…
), then pause:isPokemonValidating
isfalse
.pokemonId
becomes-1
.Performance / UI State Notes
Related Links / Issues
N/A
Before / After GIFs
Before
After
Checklist
npm run lint
)npm run build
)