As discussed earlier, an observable is an object where you can listen to events. The act of listening to events in this object is called subscription. Here, we will see the different ways in which we can subscribe to an observable and also how we can stop listening to events in this observable (unsubscribe).
We call subscribing to an observable an act of adding a function to be called when an event happens. Using bacon.js, we can be notified when a value is emitted (the
assign() methods), when an error has occurred (the
onError() method), or when our observable is closed (at the end).
The most common way of subscribing to an observable is using the
onValue() method. This method has the following signature:
So let's subscribe to
eventStream to log every event on this stream, as follows:
Bacon .fromArray([1,2,3,4,5]) .onValue((number)=>...