ngneat / until-destroy

🦊 RxJS operator that unsubscribe from observables on destroy
https://netbasal.com/
MIT License
1.74k stars 100 forks source link

Execute ngOnDestroy later #195

Closed xLama closed 2 years ago

xLama commented 2 years ago

It should be interesting execute ngOnDestroy later (with a flag) to be able prevent subscription executions in ngOnDestroy. It is usefull with NGRX Store because we want to reset store on destroy component.

POC

https://stackblitz.com/edit/angular-ivy-yke7ut?file=src%2Fapp%2Fcomponents%2Fprimary%2Fprimary.component.ts

My proposal https://github.com/xLama/until-destroy/pull/1

aalvarez-stratio commented 2 years ago

It would be very nice if we could choose went to apply the decorator functionality. For me, i also need to execute this functionality before my component's ngOnDestroy in some cases.

Jpascual55 commented 2 years ago

+1

NetanelBasal commented 2 years ago

Is there any case where you would prefer the current behavior?

xLama commented 2 years ago

Is there any case where you would prefer the current behavior?

I think both behaviors are useful. I use current behavior to exe code before unsuscriptions, like "ngOnUnsuscription", the last chance to do something.

arturovt commented 2 years ago

I don't think this somehow brings any benefit for users.

Currently, subscriptions are unsubscribed after the original ngOnDestroy is called. Which means you're capable of doing the reset logic in your ngOnDestroy. You can also do the reset logic in finalize.

What's the benefit then?