javascript: pattern to cancel subscription of RxJS subscriptions

I was reading Ben Lesh's article here:

I wonder: is the following pattern enough?

Component export class {

mounted = true;
constructor (private s: MyService) {}

onMount () {

this.s.obs.takeWhile (makePredicate ()). subscribe (...)


makePredicate () {
return () => this.mounted;

onDismount () {
this.mounted = false;


There may be an internal Boolean to which I can refer, so I may not even have to use my own Boolean, although internal APIs may change, so it's probably better to have my own Boolean.

Note that the previous example is an agnostic code (do not Angluar or React in particular)