Start in the project

An Observable can be thought of as a stream object

Processing a piece of data into a stream object can be processed using its supported operators.

Subscribe Subscription terminates the Observable with the Subscription output.

The observer the observer

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'),}; observable.subscribe(observer);Copy the code

An observer is just an object with three callbacks, each corresponding to a notification type that an Observable sends.

const ob = Observable.interval(1000);
ob.take(3).map(n => n * 2).filter(n => n > 0).subscribe(n => console.log(n));
Copy the code

Create empty() to create an Observable that emits no data and does it immediately.

Of () creates an Observable that, in turn, issues the parameters you provide, and finally issues a completion notification. Conversion operator

From () creates an Observable from an array, array-like object, Promise, iterator, or Observable. You can turn almost anything into an Observable.

ConcatMap emits the result of a cast function (and an optional resultSelector) for each value emitted by the source Observable and retrieves each projected internal Observable value sequentially. Returns an Observable that invokes the provided function based on the value emitted to the source Observable, which returns the so-called internal Observable. Each new internal Observable connects to the previous one.

The utility handles the do() execution side effect for each send on the source Observable, but returns the same Observable as the source Observable. There is a pipe() operator after version 5.5 that connects the operators inside

const source$ = range(0, 10);

source$.pipe(
  filter(x => x % 2 === 0),
  map(x => x + x),
  scan((acc, x) => acc + x, 0)
)
.subscribe(x => console.log(x))
Copy the code