-
Notifications
You must be signed in to change notification settings - Fork 26.9k
docs: fix code example in HeroService #47062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: fix code example in HeroService #47062
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good catch. I'm not sure if we need the explicit return type (PromiseLike<Hero[]>) as TypeScript will infer it for us. Personally I try to avoid adding info that TypeScript can figure out by itself, but I can see how it could be helpful for documentation / understanding.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the whole example again and suggested modification - the example is kind of broken now since it mentions cache but it doesn't use any caching in the way it is "written". So we would need to modify the code example to remove caching bits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, maybe explicit type is not so useful here that is why I removed it. Also removed the comment regarding cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming that we are talking about example on this page: https://angular.io/guide/architecture-components#introduction-to-components-and-templates , right?
If so I think that the example is fine as-is. It is just a simple code snippet that doesn't assume anything about the HeroService implementation, and specifically nothing about it being async.
Please revert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted
pkozlowski-opensource
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thnx for this PR. I've left some comments I would like to see addressed.
`getHeroes` method is syncronous and returns `this.heroes` immediately. At the same time `getAll` method in `BackendService` returns resolved Promise that is why thenable chain should be returned and used.
@pkozlowski-opensource, thank you for the comments. I've applied the changes. At the same time revert of changes in
|
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
getHeroesmethod is syncronous and returnsthis.heroesimmediately. At the same timegetAllmethod inBackendServicereturns resolved Promise that is why thenable chain should be returned and used.PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
getHeroesreturnsthis.heroesimmediately.Issue Number: N/A
What is the new behavior?
getHeroesreturns thenable Promise chain.Does this PR introduce a breaking change?
Other information