-
Notifications
You must be signed in to change notification settings - Fork 26.1k
refactor(core): separate LView-level and TView-level destroy hooks #49158
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
refactor(core): separate LView-level and TView-level destroy hooks #49158
Conversation
29350ed
to
a8df323
Compare
ce20ab6
to
6280861
Compare
f77f448
to
1873f29
Compare
1873f29
to
929d83d
Compare
929d83d
to
9bd5091
Compare
@pkozlowski-opensource Does this allow for destroy logic in inject based functions without hacks ( |
inject(DestroyRef).onDestroy is available now as per the tests |
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.
reviewed-for: public-api, circular-deps
9bd5091
to
bc96532
Compare
* are user defined, LView-specific destroy callbacks that don't have any corresponding TView | ||
* entries. | ||
*/ | ||
[ON_DESTROY_HOOKS]: Array<() => void>|null; |
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.
If would be convenient to mention here how the user defines these callsbacks. This would be useful for newcomers to this codebase.
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.
Looks very nice.
reviewed-for: public-api, fw-core
bc96532
to
348c8a8
Compare
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`.
348c8a8
to
7bd5a82
Compare
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.
Reviewed-for: size-tracking
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.
FYI, just a minor (non-blocking) comment, which can be addressed in a followup PR (if needed). I will proceed with merging this PR.
* directive is destroyed. Otherwise the callbacks run when a corresponding injector is destroyed. | ||
*/ |
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.
* 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 | |
*/ |
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.
Do we want "Developer Preview" label here as well?
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.
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 !
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; |
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.
how would I unregister the callback to avoid leaking memory in long-lived DestroyRef
s?
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.
We are going to add API for this in a follow-up PR
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. |
No description provided.