Conversation
| private _isPlatformBrowser: boolean = isPlatformBrowser(this.platformId); | ||
| | ||
| private _beforeInit: Subject<void> = new Subject<void>(); | ||
| private _onDestroy: Subject<void> = new Subject<void>(); |
There was a problem hiding this comment.
What's the purpose of _beforeInit and _onDestroy, exactly?
| return merge(...sources) | ||
| .pipe( | ||
| takeUntil(this._beforeInit), | ||
| takeUntil(this._onDestroy), |
There was a problem hiding this comment.
I'm pretty unfamiliar with some rxjs practices. Could you explain what's going on here?
There was a problem hiding this comment.
this link will answer both your questions:
http://brianflove.com/2016/12/11/anguar-2-unsubscribe-observables/
takeUntil() is a practice to make sure a subscribe gets unsubscribed for sure when some action occurs.
the action can be defined with Subject, and then when you call Subject.next() Subject.complete() (isoden added this in lines 63-64 of this pull request) you make the action happens, which in turn makes the unsubscribe happen for the subscribe that was registered to this Subject (with takeUntil).
There was a problem hiding this comment.
can't you just add a takeUntil(merge(this._beforeInit, this._onDestroy))
instead of double takeUntils ?
I changed it to be simpler.
please review :)
Thanks!