Skip to content
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

improve docs to point to memory leak if ngOnDestroy is overridden in … #4001

Merged
merged 5 commits into from
Aug 19, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions projects/ngrx.io/content/guide/component-store/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,27 @@ ComponentStore also implements the `OnDestroy` interface from `@angulare/core` t

It also exposes a `destroy$` property on the ComponentStore class that can be used instead of manually creating a `Subject` to unsubscribe from any observables created in the component.

<div class="alert is-important">
Copy link
Member

@brandonroberts brandonroberts Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not put the code snippet inside the div.alert. Put it after the closing div

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To extend upon this comment, I think it would be better to the full snippet.
Also, instead of using the markdown code-block syntax, it's better to put wrap the code within a <code-example header="books-page.component.ts"> tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i added the code snipped


**Note:** If you override the `ngOnDestroy` method in your component store, you need to call `super.ngOnDestroy()`. Otherwise a memory leak may occur.

</div>

<code-example header="movies.store.ts">
@Injectable()
export class MoviesStore extends ComponentStore&lt;MoviesState&gt; {
timdeschryver marked this conversation as resolved.
Show resolved Hide resolved

constructor() {
super({movies: []});
}

override ngOnDestroy(): void {
// 👇 add this line
super.ngOnDestroy();
}
}
</code-example>

<code-example header="books-page.component.ts">
@Component({
// ... other metadata
Expand Down