NetanelBasal/ngx-auto-unsubscribe

AutoUnsubsribe changes angular semantics of ngOnDestroy

Closed this issue · 0 comments

tmair commented

Angular allows a component to issue synchronous events within its ngOnDestroy lifecycle hook (see https://github.com/angular/angular/blame/28bdeeef3e954fd13b029f9bc9b1109d22385a1b/packages/core/test/linker/change_detection_integration_spec.ts#L1121 for a test describing the behavior)

AutoUnsubscribe changes that behavior because it first calls unsubscribe on everyting that has an unsubscribe function and then calls the ngOnDestroy hook. If you try to emit anything within the ngOnDestroy hook you will get an exception because each EventEmitter has an unsubscribe function.

It should be thought about changing the call order of the original ngOnDestory hook and the unsubscribe logic.