Reputation: 3094
const simpleObservable = new Observable( (observer) => {
observer.next("My message");
observer.complete();
})
To subscribe in sibling component,
simpleObservable.subscribe();
For subject,
const subject = new Rx.Subject();
subject.next("My message");
subject.subscribe((data) => {
console.log(data);
})
I know that main reason to use subject is for multicast and observable is unicast( each subscribed observer owns independent execution of observable).
So for just passing messages, which is more efficient and good to use?
Upvotes: 0
Views: 78
Reputation: 1105
It really depends on what you want to do with it. I suggest go for uni-casting because in multicast operation observable executes just once, and not on a per subscription basis. If the underlying observer completes, the middleman subject also completes , so any subscribers that get added in the future will not receive any data or simply
once a subject completes, future subscribers to the subject will not receive more data
also note that
Upvotes: 1