refactor(core): separate LView-level and TView-level destroy hooks#49158
refactor(core): separate LView-level and TView-level destroy hooks#49158pkozlowski-opensource wants to merge 1 commit intoangular:mainfrom
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 |
atscott
left a comment
There was a problem hiding this comment.
reviewed-for: public-api, circular-deps
9bd5091 to
bc96532
Compare
There was a problem hiding this comment.
If would be convenient to mention here how the user defines these callsbacks. This would be useful for newcomers to this codebase.
dylhunn
left a comment
There was a problem hiding this comment.
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
AndrewKushnir
left a comment
There was a problem hiding this comment.
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.
| * 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.
Do we want "Developer Preview" label here as well?
There was a problem hiding this comment.
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. |
|
|
||
| // @public | ||
| export abstract class DestroyRef { | ||
| abstract onDestroy(callback: () => void): void; |
There was a problem hiding this comment.
how would I unregister the callback to avoid leaking memory in long-lived DestroyRefs?
There was a problem hiding this comment.
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.