RxJs Flashcards
What is a “stream”?
The concept of values/events being emitted(processed) over time.
So what is an Observable in relation to a stream?
It facilitates & helps manage that stream over time. Gives methods, helpers to emit/respond to the event(s)
An Observable must take in what as an argument?
A function that defines an Observer
What is the job of the Observer
To “observe” any incoming data over time & handle(error)/emit/manipulate the value then return it.
Short answer: Execute code when a value comes through the steam
What real-life object best illustrates the concept of observables/streams
Think of an observable as a funnel (cone) that receives liquid (a stream of contents/data) over time
What hooks up Observers to an Observable?
A subscription - a subscribe method that tells the Observable that it’s being observed.
Remember a stream can be ongoing over time how do you stop an observable?
Observer.complete
An observer can emit/return data overtime w/ what method?
Observer.next()
An observer can handle an error w/ data coming in w/ what method?
Observer.error()
The power of RxJs is by having methods out of the box that does what? What are these methods called?
Operators - they can manipulate/transform the values as they arrive through the funnel(stream)
RxJs is functional in the sense that you get an input => routed to an expected output that can have operators chained one after another
true
When do you define & chain operators?
Before the subscription (subscribing w/ an observer)
Operators manipulate the data but return what?
Another observable w/ the new stream of data
A subject is an out of the box Observable you subscribe to in order to what?
EventEmitter that emits the value(s) passed over time to other observables.
Eg: var subject = new Subject() // -> Observable
subject.subscribe() // values: 1, 2, 3, 4, 5
Later subscription….
subject.subscribe() // values: 3, 4, 5
A subject is a “multicast” observable that does what when subscribed to?
Instead of invoking it registers the subscribed observer to a list (registry) of other observers that will receive updates.