RxJs Subject Class

by adil_invideo

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.7/rx.all.js"></script>
<p>
  In the preceding example we create a new Subject and a source Observable that emits an integer every second. Then we subscribe the Subject to the Observable. After that, we subscribe an Observer to the Subject itself. The Subject now behaves as an Observable.
</p>
<p>
  Next we make the Subject emit values of its own (message1 and message2). In the final result, we get the Subject’s own messages and then the proxied values from the source Observable. The values from the Observable come later because they are asynchronous,
  whereas we made the Subject’s own values immediate. Notice that even if we tell the source Observable to take the first five values, the output shows only the first three. That’s because after one second we call onCompleted on the Subject. This finishes
  the notifications to all subscriptions and overrides the take operator in this case.
</p>

JavaScript

const isPreviewing = true;
var isPreviewingSubject = new Rx.Subject();

var isPreviewingObs = isPreviewingSubject.asObservable();

let previewEnabledStream = isPreviewingObs.filter(x => x === true)

let masterJsonObs = (new Rx.Subject()).asObservable();

previewEnabledStream.takeUntil(masterJsonObs).subscribe(
	() => console.log("success"),
  () => console.log("error")
);

isPreviewingSubject.onNext(true);