-
Notifications
You must be signed in to change notification settings - Fork 61
Various tweaks #28
base: master
Are you sure you want to change the base?
Various tweaks #28
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty unfamiliar with some rxjs practices. Could you explain what's going on here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't you just add a takeUntil(merge(this._beforeInit, this._onDestroy))
instead of double takeUntil
s ?
I changed it to be simpler.
please review :)
Thanks!