fromEvent
helper function to create an observable of mouse click events:subscriber
.subscribe
method, supplying a function (or object) - also known as an observer
. This is where you can decide how to react(-ive programming) to each event. Let's walk through what happens in the previous scenario when a subscription is created:myObservable.subscribe()
will:unsubscribe
which contains clean upsubscribe
a second time will create a new event listener:Subjects
(either explicitly or behind the scenes). More on that in a future article!Array
methods. For instance, if you want to transform emitted values from an observable source, you can use map
:pipe
function is the assembly line from your observable data source through your operators. Just like raw material in a factory goes through a series of stops before it becomes a finished product, source data can pass through a pipe
-line of operators where you can manipulate, filter, and transform the data to fit your use case. It's not uncommon to use 5 (or more) operators within an observable chain, contained within the pipe
function.filtering
operators. Trying to track down a bug, or debug the flow of data through your observable stream? There are utility
operators that will do the trick. The operator categories include...fromEvent
operator:combineLatest
, concat
, merge
, startWith
, and withLatestFrom
.debounceTime
, distinctUntilChanged
, filter
, take
, and takeUntil
.switch
switch
based operators will turn off (unsubscribe) the current observable and turn on a new observable on emissions from the source. Switch operators are useful in situations you don't want (or need) more than one active observable at a time:concat
merge
n
values.mergeMap
operator, which fires off a save request on each event: