ng2-rx-collector
Angular 2 garbage collector for RxJS subscriptions.
Benefits:
- Clean, beautiful code
- One property for all component's observables
- No
ngOnDestroy
for cancelling subscriptions anymore (but still you can use it if you want)
Inspired by philipooo's beautiful answer.
Installation
npm install --save ng2-rx-collector
Usage
Import the Collected
decorator and CollectorEvent
data type (actually you can use any
instead of CollectorEvent
if this feels better) which will do all the magic.
;
Then create a property on your component which will represent the collector stopper event.
Subscribe to any observable / subject using the created property as a flag, so the observable will stop producing the output when the component is being destroyed:
public ngOnInit
That is pretty much it.
Example
This is an example you may find in the app folder.
timer.ts (representing any RxJS source):
; ;
testpage.component.ts:
;;;
License
MIT