Posts

Showing posts from June, 2019

RxJS Introductions - The first steps

Image
IntroductionThis is a essential part of Reactive programming.

An observable represents a stream, or source of data that can arrive over time.

The most common use case in RxJS is from events. This can be anything from mouse moves, button clicks, input into a text field, or even route changes.

Observables are cold, or do not activate a producer until there is a Subscription.

To create a subscription, you call the subscribe method, supplying a function (or object) - also known as an observer.

// import the fromEvent operatorimport{ fromEvent }from'rxjs';// grab button referenceconst button = document.getElementById('myButton');// create an observable of button clicksconst myObservable =fromEvent(button,'click');// for now, let's just log the event on each clickconst subscription = myObservable.subscribe(event=> console.log