Reputation:
I have a service with a couple of methods, called in various different places in my code.
class Service {
method1() {
}
method2() {
}
I'd like to be able to subscribe to those method calls, ie have an observable which emits a value whenever one of those methods is called. I realize I can do this with an Rx.Subject
but I'm wondering if there's a way to do it without, because my case doesn't satisfy the requirements listed here ie I don't need a hot observable.
Upvotes: 3
Views: 148
Reputation: 39222
Use a subject. Your desired observable is, by definition, hot.
Read through the Hot and Cold Observables article again. Here's the important bit:
Hot observables do not cause subscription side effects.
Cold observables do cause subscription side effects; however, we must assume that any observable with an unknown temperature is cold, and sometimes that assumption will be wrong; therefore, a more accurate definition is:
Cold observables may cause subscription side effects.
In your case, code is calling your methods whether or not anything "subscribes" to be notified when the methods are called. Subscribing for notifications does not trigger any activity or changes in behavior. In fact, late subscribers will "miss" calls made before they subscribed.
Upvotes: 4