rxjs5

RXJS control observable invocation

元气小坏坏 提交于 2019-12-18 18:59:27
问题 I use RxJs version 5 within my Angular 2 project. I want to create some observables but I don't want the observables being invoked immediately. In version 4 you could control the invocation with (for example) the Controlled command or Pausable Buffers. But that functionality is not (yet) available in version 5. How can I get the this kind of functionality in RxJs 5? My ultimate goal is to queue the created observables and invoke them one by one. The next one is only invoked when the previous

Angular and RxJS imports

跟風遠走 提交于 2019-12-18 15:04:36
问题 I've always known to import my Observable operators separately to limit the load times. However I've noticed something today that I hope someone could please explain to me. I am using IntelliJ/WebStorm with Webpack. Let's say on a page in my ngOnInit I have an http call: ngOnInit() { this.http.get('https//:google.com').map(e => e); } If I don't import the map operator the compiler will complain, so I import it like this: import 'rxjs/add/operator/map'; All is good in the world. Until I need

RxJS 5, converting an observable to a BehaviorSubject(?)

偶尔善良 提交于 2019-12-18 14:14:42
问题 I have a parent observable that, once it has a subscriber, will do a lookup and emit a single value, then complete. I'd like to convert that into an observable (or behavior subject or whatever works) that does the following: once it has at least one subscriber, it gets the result from the parent observable (once). Then it emits that value to all of its subscribers, and also emits that single value to all future subscribers, when they subscribe. It should continue with this behavior even if

'Observable<T>' is not a class derived from 'Observable<T>'

纵饮孤独 提交于 2019-12-18 12:05:34
问题 When trying to extend a class from a class in a node_modules the typescript compiler throws a error saying: Property 'source' is protected but type 'Observable<T>' is not a class derived from 'Observable<T>'. This only happens when the base class is from a node_module . The base class looks like: import {Observable} from "rxjs/Observable"; export abstract class TestBase<T> { request(options: any):Observable<T> { return Observable.throw(new Error('TestBase is abstract class. Extend it and

RxJS - .subscribe() vs .publish().connect()

筅森魡賤 提交于 2019-12-18 11:09:12
问题 This is mainly an RxJs best practice/approach question, since my POC code works but I'm brand new to RxJs. The question boils down to .subscribe() vs .publish().connect() , since they both appear to do the same thing. In my angular2 app, I have a button that calls a function to log the user out, which calls a function in my service that performs some server side actions and returns me a URL to redirect the user to. In order to initiate the request I call .subscribe() to cause the observable

Angular2 2.0.x and Rx 5 beta.12 bundle

别等时光非礼了梦想. 提交于 2019-12-18 09:34:18
问题 I am currently updating the dependencies of my project which uses the Angular2 npm packages and therefore RxJs as well. I am updating to the 2.0.2 stable release of angular which depends on Rx5 beta.12. For my web application i only deploy the Rx.min.js bundle and load it with a script tag in my index.html file. That approach worked perfectly before with the Rx umd bundle, but causes errors meanwhile, since it appears to me that the contributors of RxJs dropped the different bundle versions

How to wait for guards in Angular

☆樱花仙子☆ 提交于 2019-12-18 04:53:19
问题 If i specify three guards on a route, it seems as though all guards are evaluated immediately. {path: '', component: OptionsComponent, canActivate: [ GuardOne, GuardTwo, GuardThree]} The problem I have is I don't want GuardTwo to run until GuardOne has finished. Is there any way to achieve this? 回答1: I don't think that's possible in the 4.1.3. Here is the code that runs the guards: private runCanActivate(future: ActivatedRouteSnapshot): Observable<boolean> { const canActivate = future.

“async” pipe not rendering the stream updates

一世执手 提交于 2019-12-18 03:17:08
问题 Trying to render the window size on window resize through a stream in an angular 2 component utilizing an async pipe: <h2>Size: {{size$ | async | json}}</h2> const windowSize$ = new BehaviorSubject(getWindowSize()); Observable.fromEvent(window, 'resize') .map(getWindowSize) .subscribe(windowSize$); function getWindowSize() { return { height: window.innerHeight, width: window.innerWidth }; } @Component({ selector: 'my-app', providers: [], template: ` <div> <h2>Size: {{size$ | async | json}}<

rxjs 5 publishReplay refCount

岁酱吖の 提交于 2019-12-18 03:08:16
问题 I can't figure out how publishReplay().refCount() works. For example (https://jsfiddle.net/7o3a45L1/): var source = Rx.Observable.create(observer => { console.log("call"); // expensive http request observer.next(5); }).publishReplay().refCount(); subscription1 = source.subscribe({next: (v) => console.log('observerA: ' + v)}); subscription1.unsubscribe(); console.log(""); subscription2 = source.subscribe({next: (v) => console.log('observerB: ' + v)}); subscription2.unsubscribe(); console.log("

Angular 2 RxJS Observable: RetryWhen filter retry on error Status

一世执手 提交于 2019-12-17 20:28:02
问题 I am using Angular 2 HTTP library which returns an observable. I want to implement retry on certain error status/code. I have an issue, if the error is not 429, Observable.of(error) is getting executed in error case to retry, but when all your 2 retry fails the execution of flow goes to success block instead of catch block. How to make execution of flow to catch block in all retry fails? return this.http.get(url,options) .retryWhen((errors) => { return errors .mergeMap((error) => (error