I'm trying to return an observable from a function that uses Rx.Subject internally. Of course, as with any good API, the implementation details should be entirely abstracted from the consumer. However, using Subject.asObservable() it appears possible for any consumer to issue new values to all observers.
Example:
const subject = new Rx.Subject();
const observable = subject.asObservable();
observable.source === subject; // true
observable.forEach(value => console.log(value));
observable.source.next('Hello');
// Causes the forEach above to print "Hello"
So my question is, is there a built-in way to expose an Observable to consumers without giving them access to the original subject? If not this is clearly bad design on RxJs' part.
NOTE: This is for RxJS v5