gdirk07 / PokemonChecker

Playing around with APIs
https://gdirk07.github.io/PokemonChecker/
0 stars 0 forks source link

Decoupled PokemonFactory from PokemonDisplay.tsx #86

Closed jeremy-jtlo closed 2 years ago

jeremy-jtlo commented 2 years ago

Removed a small thorn from PokemonDisplay.tsx. As a view class, it really has no business trying to create DTOs. For this first pass fix, the service now performs the fetch and uses the factory to return a proper DTO, as it should have done in the first place.

The getPokemon method in the service was a simple fetch + dump of raw JSON. Because of ESLint, that's now been converted to an async function.

In order to maintain class context I've changed the declaration to an arrow function (some more details on that here and here.)

If the get method was declared in this style:

public getPokemon(url: string) { ... }

Then the inside of the method would say this is undefined. It's been converted to an arrow:

public getPokemon = async (url: string) => { ... }

And now it remembers its class properties.

gdirk07 commented 2 years ago

This looks good, it did break some functionality in that ability names are using the given name and not the localized name. But that's another issue since I kind of hacked it together, I'll create a new issue for it and create a unit test for it