Introducing RxJS6! - Ben Lesh
Why Stack Overflow recommends it
Stack Overflow users link it when answering RxJS 6 migration questions about imports, pipeable operators and why prototype patching was dropped.
Recommended by 5 people across 5 different months, 2018 to 2021.
What it is
A conference talk from ng-conf by Ben Lesh, the RxJS lead, introducing RxJS 6. It covers the new import paths, the move from prototype patching to pipeable operators, and changes to error handling.
What people said
Recommends siva636 · 2018-04 · Stack Overflow · on “Where is RxJS 6 static merge?”
Importing has been made easy in RxJS 6: import { merge } from 'rxjs'; You may want to read the official migration guide [LINK] . Another useful resource regarding importing in RxJS 6 is this talk [this video] by Ben Lesh who is the RxJS lead.
Recommends alexKhymenko · 2018-05 · Stack Overflow · on “How to import only used operators in RxJS 6 like older RxJS without requiring rxjs-compat?”
Now You need to import functions that You want to use. Never use import from 'rxjs' Use with destructuring import { Observable } from 'rxjs' Import operators from 'rxjs/operators' Static functions from 'rxjs' So, for example, you need to use operator 'map' you will import it import { map } 'rxjs/operators'; And then you use it with pipe observable.pipe(map(() => { some function })) For better understanding read Migration Guide [LINK] or watch awesome video from ng-conf [this video]
Recommends Bunyamin Coskuner · 2018-06 · Stack Overflow · on “import ES6 modules with Angular and rxjs”
That's actually old way to import operators. import 'rxjs/add/observable/of'; is actually prototyping method of to Observable . When you import that, every Observable object has of method available. That's why you should put those import lines in a root file like app.module . However, as I told you at the beginning, it is the old way. With RxJs 5.5, pipeable operators came into play. You can and should import operators/observables as follows import { of } from 'rxjs/observable/of'; const myObs = of('some value'); With this way, operators and observables became tree-shakable. Webpack will not put unused operators into your output bundle. Update Let's say you are using bunch of operators and y
Recommends MattYao · 2018-07 · Stack Overflow · on “Angular 6: Observable HTTPClient”
There are a couple of breaking changes in RxJS v6 that has been adopted by Angular6 that you need to be aware of: The different way of import statement of observables and operators. So you will need to add operators in this way at the top of the component controller: import { interval } from 'rxjs'; import { startWith, mergeMap } from 'rxjs/operators'; Use pipe() as a method to chain your operators, the old way of chaining them will not work: // COMPONENT export class ViewComponent { constructor (private vs : ViewService) {} ngOnInit () { const obs$ = interval(1000).pipe( // This is your main observer chain startWith(0), mergeMap(res => this.vs.foo()) // This will start a sub-chain of observ
Recommends Homan · 2021-03 · Stack Overflow · on “Javascript when to use prototypes”
Just including a video link here for reference, when not to use prototypes: [this video] Here is Ben Lesh's talk from NGConf, why rxjs removed patching prototype (chainable functions) in favor of pipeable functions.
Cites cartant · 2018-06 · Stack Overflow · on “RXJS - Catch exception thrown by observer”
The short answer is that you can't and you shouldn't. How would an observable source know what kinds of errors could be thrown by its observers? The long answer is that the error handling in RxJS has changed - for the better - in version 6. If you look at the implementation of next [LINK] in Subject you'll see that there is no error handling: next(value?: T) { if (this.closed) { throw new ObjectUnsubscribedError(); } if (!this.isStopped) { const { observers } = this; const len = observers.length; const copy = observers.slice(); for (let i = 0; i < len; i++) { copy[i].next(value); } } } The subject just loops through its observers and next on each. However, each observer is wrapped in a Subsc
Cites cartant · 2018-09 · Stack Overflow · on “RXJS Subject - stopping errors from propagating”
This is a known problem with RxJS v5 and it's something that's been addressed in v6 - in which the synchronous error handling has been changed [LINK] . In v6, what you are seeing will no longer happen. Instead, errors thrown from within 'listeners' will be rethrown asynchronously and will be seen by the application as unhandled errors. For more information, see this video [this video] .