Angular RxJS Flashcards

1
Q

RxJS is Reactive Extension for Javascript is a library …

A

for composing asynchronous and event-based programs by using observable sequences

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

RxJs is so useful that angular implemented it in its features

A

Routing,
Reactive Forms,
HttpClient

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Observer is an object that monitors a stream. Observer response to notifications:

A
  • next() - handle next item emitted in the steam
  • error() - handle errors
  • complete() - perform final processing or cleanup when stream is complete
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Observer is

A

a collection of callbacks that knows how to listen to values delivered by the observable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

An observer is a

A

javascript object that defines the handlers for the notificatoins you receive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In RxJS an Observer is

A

also defined as an interface with next, error and complete methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Var vs let vs const

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Observables are lazy and they

A

don’t execute when defined. Only when subscribed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Observer is

A

set of callbacks to observe handling next, error and complete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Observable is (or stream)

A

sequence of emitted items

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In how main ways an observer can be stopped

A
  • Call complete method
  • Using completing operator (of, for, take)
  • Throw an error, does not call complete
  • Unsubscribe, does not call complete
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Unsubscribing from observable that does not complete on it’s own helps us with

A

avoiding memory leaks in the application

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In angular we often work with observables that angular create for us

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Creating an observable (recommendet technique) is to use

A

a built-in creating function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Funciton of(‘Apple1’, ‘Apple2’) is

A

is creating an observable using a set of items emitting each value and then completing the stream

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

from([‘ads’, ‘we’]) does

A

creates an observable from an array or other data structure, emitting each individual value from that structure and then completing the stream

17
Q

of and from are static functions

A
18
Q
of vs from
const apples = ['Apple1', 'Apple2'];
A

of(apples) // [Apple1, Apple2]
of(…apples) // Apple1, Apple2
from(apples) // Apple1, Apple2

19
Q

few ways for Creating an observable

A
  • fromEvent - creates an observable from any document, object model or or DOM event
  • inverval(1000) - emits sequential number at a defined interval
20
Q

Observable is

A

any stream of data

21
Q

Observer is

A

Observers the stream

Methods to process notifications from the stream are next, error, complete

22
Q

Subscriber is

A

an observer that can unsebscribe

23
Q

Subscription is

A

represents the execution of an observable.

subscribe() returns a subscription and we then can ubsubscribe

24
Q

Creating an observable can be done through

A
  • Constructor - bad technique
  • Creating functions - of, from ,from event, interval ….
  • Create an observable form anything
  • Returned from an angular feature
    - Forms - valuechanges
    - Routing: paramMap
    - Http: get
    - …….
25
Q

To avoid memory leaks we should

A
always stop our observables.
Call complete()
of, from ... automatically unsubscribe  and execute complete().
Throwing an error also unsubscribed
sub.unsubscribe()
26
Q

RxJS operator is a function that

A

transforms and manipulates items in an observable stream.

They are applied by using the observable pipe method

27
Q

async pipe

A

Automatically subscribes to the observable when the component is initialized.
Returns each emitted value.
When a new item is emitted, component is marked to be checked for changes.
Unsubscribes automatically when component is destroyed

28
Q

What is the difference between an Observable and a function?

A

Observables can “return” multiple values over time, something which functions cannot.