fromEvent
explained - element events as streams
fromEvent(element, eventName, options)
=>
observable object
This method generates anobservablesteam from events firering on an element. You can then addsubscriptionson this observable. Conceptually you can view it like this: ThefromEventgives you a water tap, out of which comes data in the form of events.
The subscription can in that perspective be viewed as a hose: when you attach the hose to the water tap you have a place where events streams into. The events are the parameters in yousubscribe('event data').
You can attach more hoses (the subscriptions ) to this water tap (the observable ), it is you can add more than one subscription to the observable object retured byfromEvent.
mouseMoveObservable$
mouseMove.subscribe(({ clientX, clientY }) => {
...
// your code
...
})
mouseMoveObservable$
observable stream
-
-
Naming convension - postfix with
It is a good practice to postfix the variable name of an observable stream with a$$. The stream in this pen on mousemove events is for instance namedmouseMoveObservable$.