map vs switchMap in RxJS

Both operators are different. switchMap: Maps values to observable. Cancels the previous inner observable. Eg: fromEvent(document, ‘click’) .pipe( // restart counter on every click // First click: 0, 1, 2… // Second click: cancels the previous interval and starts new one. 0, 1, 2… switchMap(() => interval(1000)) ) .subscribe(console.log); map: Add projection with each value. … Read more

How do I get around this “Subject incorrectly extends Observable” error in TypeScript 2.4 and RxJS 5.x?

Solution RxJS 5.4.2 should now work perfectly with TypeScript 2.4.1. Simply upgrade to 5.4.2+ if possible. npm install –save rxjs@^5.4.2 Then try restarting your editor and/or recompile if you don’t see an immediate change. If not, the below solution should work. Why it’s happening TypeScript 2.4 has a strictness change, and Subject<T> isn’t lifting to … Read more

Handling refresh tokens using rxjs

From a quick look at your code I would say that your problem seems to be that you are not flattening the Observable that is returned from the refresh service. The catch operator expects that you will return an Observable that it will concatenate onto the end of the failed Observable so that the down … Read more

redux-observable – dispatch multiple redux actions in a single epic

There is no requirement that you make a one-to-one in/out ratio. So you can emit multiple actions using mergeMap (aka flatMap) if you need to: const loaded = (results) => ({type: ‘RESULTS_LOADED’, results}); const otherAction = (results) => ({type: ‘MY_OTHER_ACTION’, results}); searchEpic = (action$) => action$ .ofType(‘SEARCH’) .mergeMap( Observable .fromPromise(searchPromise) // Flattens this into two … Read more

Does Subject.complete() unsubscribe all listeners?

If you want to be sure it removes all Observers you can check it for yourself in https://github.com/ReactiveX/rxjs/blob/master/src/internal/Subject.ts#L91. It calls complete() on all Observers (Observers are typically just dumb objects implementing Observer interface) and then sets this.observers.length = 0;. So the answer is yes. Your approach is valid, it’s basically the same as Angular2 regularly … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)