Angular RxJS Flashcards
RxJS is Reactive Extension for Javascript is a library …
for composing asynchronous and event-based programs by using observable sequences
RxJs is so useful that angular implemented it in its features
Routing,
Reactive Forms,
HttpClient
Observer is an object that monitors a stream. Observer response to notifications:
- next() - handle next item emitted in the steam
- error() - handle errors
- complete() - perform final processing or cleanup when stream is complete
Observer is
a collection of callbacks that knows how to listen to values delivered by the observable
An observer is a
javascript object that defines the handlers for the notificatoins you receive
In RxJS an Observer is
also defined as an interface with next, error and complete methods
Var vs let vs const
var declarations are globally scoped or function scoped while let and const are block scoped.
var variables can be updated and re-declared within its scope; let variables can be updated but not re-declared; const variables can neither be updated nor re-declared.
They are all hoisted to the top of their scope. But while var variables are initialized with undefined, let and const variables are not initialized.
While var and let can be declared without being initialized, const must be initialized during declaration.
Observables are lazy and they
don’t execute when defined. Only when subscribed
Observer is
set of callbacks to observe handling next, error and complete
Observable is (or stream)
sequence of emitted items
In how main ways an observer can be stopped
- Call complete method
- Using completing operator (of, for, take)
- Throw an error, does not call complete
- Unsubscribe, does not call complete
Unsubscribing from observable that does not complete on it’s own helps us with
avoiding memory leaks in the application
In angular we often work with observables that angular create for us
Creating an observable (recommendet technique) is to use
a built-in creating function
Funciton of(‘Apple1’, ‘Apple2’) is
is creating an observable using a set of items emitting each value and then completing the stream