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)=>console.log(number));
This code gives you the following output to the console:
1 2 3 4 5
This function can be used for any type of observable (EventStream and Property). The only difference is that in Properties, if the initial value of the Property exists, then it triggers the onValue() function. Check out the following code:
var initialValue =0; Bacon .fromArray([1,2,3,4,5]) .toProperty(initialValue) ...