Random 2 Flashcards

1
Q

There are several ways of getting the latest value from a Subject or Observable in a “Rx-y” way

A
  1. Using BehaviorSubject: But actually subscribing to it. When you first subscribe to BehaviorSubject it will synchronously send the previous value it received or was initialized with.
  2. Using a ReplaySubject(N): This will cache N values and replay them to new subscribers.
  3. A.withLatestFrom(B): Use this operator to get the most recent value from observable Bwhen observable A emits. Will give you both values in an array [a, b].
  4. A.combineLatest(B): Use this operator to get the most recent values from A and B every time either A or B emits. Will give you both values in an array.
  5. shareReplay(): Makes an Observable multicast through a ReplaySubject, but allows you to retry the observable on error. (Basically it gives you that promise-y caching behavior).
  6. publishReplay(), publishBehavior(), multicast(subject: BehaviorSubject | ReplaySubject), etc: Other operators that leverage BehaviorSubject and ReplaySubject. Different flavors of the same thing, they basically multicast the source observable by funneling all notifications through a subject. You need to call connect() to subscribe to the source with the subject.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Operators that originate new Observables

A
  • Create — create an Observable from scratch by calling observer methods programmatically
  • Defer — do not create the Observable until the observer subscribes, and create a fresh Observable for each observer
  • Empty/Never/Throw — create Observables that have very precise and limited behavior
  • From — convert some other object or data structure into an Observable
  • Interval — create an Observable that emits a sequence of integers spaced by a particular time interval
  • Just — convert an object or a set of objects into an Observable that emits that or those objects
  • Range — create an Observable that emits a range of sequential integers
  • Repeat — create an Observable that emits a particular item or sequence of items repeatedly
  • Start — create an Observable that emits the return value of a function
  • Timer — create an Observable that emits a single item after a given delay
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

create ReplaySubject that buffers the 3 last values but with a window time of 500ms

A

var subject = new Rx.ReplaySubject(3, 500);

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

Transforming Observables

Operators that transform items that are emitted by an Observable

A
  • Buffer — periodically gather items from an Observable into bundles and emit these bundles rather than emitting the items one at a time
  • FlatMap — transform the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable
  • GroupBy — divide an Observable into a set of Observables that each emit a different group of items from the original Observable, organized by key
  • Map — transform the items emitted by an Observable by applying a function to each item
  • Scan — apply a function to each item emitted by an Observable, sequentially, and emit each successive value
  • Window — periodically subdivide items from an Observable into Observable windows and emit these windows rather than emitting the items one at a time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Filtering Observables

Operators that selectively emit items from a source Observable.

A
  • Debounce — only emit an item from an Observable if a particular timespan has passed without it emitting another item
  • Distinct — suppress duplicate items emitted by an Observable
  • ElementAt — emit only item n emitted by an Observable
  • Filter — emit only those items from an Observable that pass a predicate test
  • First — emit only the first item, or the first item that meets a condition, from an Observable
  • IgnoreElements — do not emit any items from an Observable but mirror its termination notification
  • Last — emit only the last item emitted by an Observable
  • Sample — emit the most recent item emitted by an Observable within periodic time intervals
  • Skip — suppress the first n items emitted by an Observable
  • SkipLast — suppress the last n items emitted by an Observable
  • Take — emit only the first n items emitted by an Observable
  • TakeLast — emit only the last n items emitted by an Observable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Combining Observables

Operators that work with multiple source Observables to create a single Observable

A
  • And/Then/When — combine sets of items emitted by two or more Observables by means of Patternand Plan intermediaries
  • CombineLatest — when an item is emitted by either of two Observables, combine the latest item emitted by each Observable via a specified function and emit items based on the results of this function
  • Join — combine items emitted by two Observables whenever an item from one Observable is emitted during a time window defined according to an item emitted by the other Observable
  • Merge — combine multiple Observables into one by merging their emissions
  • StartWith — emit a specified sequence of items before beginning to emit the items from the source Observable
  • Switch — convert an Observable that emits Observables into a single Observable that emits the items emitted by the most-recently-emitted of those Observables
  • Zip — combine the emissions of multiple Observables together via a specified function and emit single items for each combination based on the results of this function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Error Handling Operators

Operators that help to recover from error notifications from an Observable

A
  • Catch — recover from an onError notification by continuing the sequence without error
  • Retry — if a source Observable sends an onError notification, resubscribe to it in the hopes that it will complete without error
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Observable Utility Operators

A toolbox of useful Operators for working with Observables

A
  • Delay — shift the emissions from an Observable forward in time by a particular amount
  • Do — register an action to take upon a variety of Observable lifecycle events
  • Materialize/Dematerialize — represent both the items emitted and the notifications sent as emitted items, or reverse this process
  • ObserveOn — specify the scheduler on which an observer will observe this Observable
  • Serialize — force an Observable to make serialized calls and to be well-behaved
  • Subscribe — operate upon the emissions and notifications from an Observable
  • SubscribeOn — specify the scheduler an Observable should use when it is subscribed to
  • TimeInterval — convert an Observable that emits items into one that emits indications of the amount of time elapsed between those emissions
  • Timeout — mirror the source Observable, but issue an error notification if a particular period of time elapses without any emitted items
  • Timestamp — attach a timestamp to each item emitted by an Observable
  • Using — create a disposable resource that has the same lifespan as the Observable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Conditional and Boolean Operators

Operators that evaluate one or more Observables or items emitted by Observables

A
  • All — determine whether all items emitted by an Observable meet some criteria
  • Amb — given two or more source Observables, emit all of the items from only the first of these Observables to emit an item
  • Contains — determine whether an Observable emits a particular item or not
  • DefaultIfEmpty — emit items from the source Observable, or a default item if the source Observable emits nothing
  • SequenceEqual — determine whether two Observables emit the same sequence of items
  • SkipUntil — discard items emitted by an Observable until a second Observable emits an item
  • SkipWhile — discard items emitted by an Observable until a specified condition becomes false
  • TakeUntil — discard items emitted by an Observable after a second Observable emits an item or terminates
  • TakeWhile — discard items emitted by an Observable after a specified condition becomes false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  • backpressure operators — strategies for coping with Observables that produce items more rapidly than their observers consume them
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Connectable Observable Operators

Specialty Observables that have more precisely-controlled subscription dynamics

A
  • Connect — instruct a connectable Observable to begin emitting items to its subscribers
  • Publish — convert an ordinary Observable into a connectable Observable
  • RefCount — make a Connectable Observable behave like an ordinary Observable
  • Replay — ensure that all observers see the same sequence of emitted items, even if they subscribe after the Observable has begun emitting items
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Operators to Convert Observables

  • To — convert an Observable into another object or data structure
A

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

Default font size.

A

This is default font but with some bold words.

No line break above.

  • Two bulleted items
  • Second bulleted item
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
A

Observer

What is an Observer? An Observer is a consumer of values delivered by an Observable. Observers are simply a set of callbacks, one for each type of notification delivered by the Observable: next, error, and complete.

Observer

What is an Observer? An Observer is a consumer of values delivered by an Observable. Observers are simply a set of callbacks, one for each type of notification delivered by the Observable: next, error, and complete.

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

What is an Observer

A

Observer

What is an Observer? An Observer is a consumer of values delivered by an Observable. Observers are simply a set of callbacks, one for each type of notification delivered by the Observable: next, error, and complete.

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

The following is an example of a typical Observer object:

A

var observer = {

` next: x => console.log(‘Observer got a next value: ‘ + x),`

` error: err => console.error(‘Observer got an error: ‘ + err),`

` complete: () => console.log(‘Observer got a complete notification’),`

};

17
Q

More sample code, without code tag.

A

var observer = {
next: x => console.log(‘Observer got a next value: ‘ + x),
error: err => console.error(‘Observer got an error: ‘ + err),
complete: () => console.log(‘Observer got a complete notification’),
};

18
Q

When subscribing to an Observable, you may also just provide the callbacks as arguments, without being attached to an Observer object, for instance like this:

A

observable.subscribe(x => console.log(‘Observer got a next value: ‘ + x));

19
Q
A
20
Q

null (scheduler type)

A

By not passing any scheduler, notifications are delivered synchronously and recursively. Use this for constant-time operations or tail recursive operations.

21
Q

Rx.Scheduler.queue

A

Schedules on a queue in the current event frame (trampoline scheduler). Use this for iteration operations.

22
Q

Rx.Scheduler.asap

A

Schedules on the micro task queue, which uses the fastest transport mechanism available, either Node.js’ process.nextTick() or Web Worker MessageChannel or setTimeout or others. Use this for asynchronous conversions.

23
Q

Rx.Scheduler.async

A

Schedules work with setInterval. Use this for time-based operations.