I've been working with RxJS for a short while and I still cant get to grips with Subjects.
The documentation has the following
var source = Rx.Observable.from([1, 2, 3]);
var subject = new Rx.Subject();
var multicasted = source.multicast(subject);
But how is this different from?:
var source = Rx.Observable.from([1, 2, 3]);
var multicasted = source.share();
I often have to create classes that expose Observables but I don't want to expose Subjects as they have the next function. I don't want using classes to be able to push things into the pipeline. I currently do them like this:
var observer = null;
var sourceToBeExposed = Rx.Observable.create(ob => {
observer = ob;
}).share();
// then later
if (observer != null)
observer.next(newValue);
I'm struggling to work out why Subjects exist and what their main purpose is for. I'm sure I'm missing something important. Are there any good examples of Subjects someone can point me to?