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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): separate LView-level and TView-level destroy hooks #49158

Conversation

pkozlowski-opensource
Copy link
Member

No description provided.

@pkozlowski-opensource pkozlowski-opensource added the area: core Issues related to the framework runtime label Feb 22, 2023
@ngbot ngbot bot added this to the Backlog milestone Feb 22, 2023
@pkozlowski-opensource pkozlowski-opensource added the action: review The PR is still awaiting reviews from at least one requested reviewer label Feb 22, 2023
@pkozlowski-opensource pkozlowski-opensource marked this pull request as draft February 22, 2023 11:21
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Feb 22, 2023
@pkozlowski-opensource pkozlowski-opensource force-pushed the lview_on_destroy branch 4 times, most recently from ce20ab6 to 6280861 Compare February 22, 2023 15:36
@pkozlowski-opensource pkozlowski-opensource marked this pull request as ready for review February 22, 2023 15:49
@pkozlowski-opensource pkozlowski-opensource force-pushed the lview_on_destroy branch 2 times, most recently from f77f448 to 1873f29 Compare February 22, 2023 17:12
@Harpush
Copy link

Harpush commented Feb 24, 2023

@pkozlowski-opensource Does this allow for destroy logic in inject based functions without hacks (inject(ChangeDetectorRef) as ViewRef)? If it is please make it public API.

@gmfun
Copy link

gmfun commented Feb 25, 2023

@pkozlowski-opensource Does this allow for destroy logic in inject based functions without hacks (inject(ChangeDetectorRef) as ViewRef)? If it is please make it public API.

inject(DestroyRef).onDestroy is available now as per the tests

@pullapprove pullapprove bot requested a review from atscott February 27, 2023 17:11
Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

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

reviewed-for: public-api, circular-deps

packages/core/src/linker/destroy_ref.ts Outdated Show resolved Hide resolved
packages/core/src/linker/destroy_ref.ts Show resolved Hide resolved
packages/core/src/render3/interfaces/view.ts Show resolved Hide resolved
* are user defined, LView-specific destroy callbacks that don't have any corresponding TView
* entries.
*/
[ON_DESTROY_HOOKS]: Array<() => void>|null;
Copy link
Member

Choose a reason for hiding this comment

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

If would be convenient to mention here how the user defines these callsbacks. This would be useful for newcomers to this codebase.

packages/core/test/acceptance/destroy_ref_spec.ts Outdated Show resolved Hide resolved
packages/core/src/di/r3_injector.ts Outdated Show resolved Hide resolved
@pullapprove pullapprove bot requested a review from alxhub February 28, 2023 17:08
Copy link
Contributor

@dylhunn dylhunn left a comment

Choose a reason for hiding this comment

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

Looks very nice.
reviewed-for: public-api, fw-core

DestroyRef represents a concept of lifecycle scope where destroy
callbacks can be registered. Such callbacks are automatically
executed when a given scope ends it lifecycle.

In practice the most common  lifecycle scopes would be represented by:
 - a component or en embedded view;
 - instance of `EnvironnementInjector`.
@pkozlowski-opensource pkozlowski-opensource added the target: major This PR is targeted for the next major release label Feb 28, 2023
@pullapprove pullapprove bot requested a review from dylhunn February 28, 2023 19:27
Copy link
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

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

Reviewed-for: size-tracking

@pkozlowski-opensource pkozlowski-opensource removed the request for review from dylhunn February 28, 2023 19:33
@pkozlowski-opensource pkozlowski-opensource added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 28, 2023
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

FYI, just a minor (non-blocking) comment, which can be addressed in a followup PR (if needed). I will proceed with merging this PR.

Comment on lines +18 to +19
* directive is destroyed. Otherwise the callbacks run when a corresponding injector is destroyed.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* directive is destroyed. Otherwise the callbacks run when a corresponding injector is destroyed.
*/
* directive is destroyed. Otherwise the callbacks run when a corresponding injector is destroyed.
*
* @publicApi
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want "Developer Preview" label here as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I'm not sure :-) I do think that we might want to have this API regardless of other dev-preview work where it is going to be used primarily.

But yep, this is good discussion to be had! I would appreciate if we could get it in (was trying to make it green for a while...) and decide on the API flag in a separate PR.

Thnx for checking @AndrewKushnir !

@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit 0f5c800.

@@ -436,6 +436,11 @@ export const defineInjectable: typeof 傻傻defineInjectable;
// @public
export function destroyPlatform(): void;

// @public
export abstract class DestroyRef {
abstract onDestroy(callback: () => void): void;
Copy link

Choose a reason for hiding this comment

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

how would I unregister the callback to avoid leaking memory in long-lived DestroyRefs?

Copy link
Member Author

Choose a reason for hiding this comment

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

We are going to add API for this in a follow-up PR

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime detected: feature PR contains a feature commit target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet