rxjs

Conditional emission delays with rxjs

匆匆过客 提交于 2019-12-06 00:43:39
From picture to code? How to get the Out observable from Data and Gates? Data is an observable of any kind e.g. JSON objects to be sent to a remote backend Gates is a boolean observable, where the ticks correspond to true and the crosses to false. For example, Internet connectivity whereby true means the network became accessible and false reflects a disconnection. Out is the resulting observable, which emits the same as Data, sometimes immediately, sometimes with a delay, depending on the gate that preceded. For instance, I could subscribe to the Out in order to post the emitted JSON objects

Angular 2 - Typescript: TS2322: Type 'Subscription' is not assignable to type 'Observable<MouseEvent>'

一世执手 提交于 2019-12-06 00:04:17
I am using the click-outside directive from this plunk --> http://embed.plnkr.co/v7BMUv/ My TS compiler is throwing the following errors: TS2322: Type 'Subscription' is not assignable to type 'Observable'. Property '_isScalar' is missing in type 'Subscription'. TS2339 Property 'unsubscribe' does not exist on type 'Observable'. My tsconfig.json: { "compileOnSave": false, "compilerOptions": { "target": "es6", "module": "system", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "suppressImplicitAnyIndexErrors":

Conditionally choose observable in RxJS

假如想象 提交于 2019-12-05 23:44:48
I would like to know how to create a new observable that will return one of two other observables based on if the first observable is empty (without calling the second observable by default). Eg: // scenario 1 let obs1 = Observable.empty(); let obs2 = Observable.of([1,2,3]); // This line doesn't work, but is essentially what I'm attempting to do let obs3 = (obs1.isEmpty()) ? obs2 : obs1; obs3.subscribe( i => console.log('Next: ', i)); // Next: 1 // Next: 2 // Next: 3 // Complete // scenario 2 let obs1 = Observable.of([6,7,8]); let obs2 = Observable.of([1,2,3]); // This line doesn't work, but

Denormalizing ngrx store- setting up selectors?

半城伤御伤魂 提交于 2019-12-05 22:56:43
I am currently working with a somewhat complicated (deep) structure within an ngrx project. It can be thought of as an array of parent objects, with multiple levels of child objects. It is normalized/flattened on the server side, and my the feature within my store looks something like this: rootObjs: { level1: { byId: { 'lvl1_1': {id: 'lvl1_1', label: '[Lvl 1]: 1', ui_open: true, children: ['lvl2_1', 'lvl2_3']}, 'lvl1_2': {id: 'lvl1_2', label: '[Lvl 1]: 2', ui_open: false, children: ['lvl2_2']} }, allIds: [ 'lvl1_1', 'lvl1_2' ] }, level2: { byId: { 'lvl2_1': {id: 'lvl2_1', label: '[Lvl 2]: 1',

RxJS5 finalize operator not called

二次信任 提交于 2019-12-05 22:37:21
问题 I'm trying to trigger a callback when all my observables are executed. In my other, older project i used finally like so and that worked like a charm: this.myService.callDummy() .finally(() => console.log('Works!')) .subscribe(result => ...) But now I'm using a newer version of RxJS with Pipeable operators , but the finally call (now renamed to finalize ) never gets executed. There is little information to be found and I'm not sure what I'm doing wrong. combineLatest( this.route.queryParams,

Angular2 rxjs - switchmap catch error

大憨熊 提交于 2019-12-05 22:29:16
问题 I'd like to be able to handle any errors that error when calling this.authService.refreshToken() . Can errors be handled within the switchmap block, or how do I go about handling an error in this case? post3(endpoint: string, body: string) : Observable<any> { if (this.authService.tokenRequiresRefresh()) { this.authService.tokenIsBeingRefreshed.next(true); return this.authService.refreshToken().switchMap( data => { this.authService.refreshTokenSuccessHandler(data); if (this.authService

RxJS catch **and** retry an Observable

女生的网名这么多〃 提交于 2019-12-05 22:01:04
问题 My use case is to map an Observable to redux actions of success and failure. I make a network call (with a function that gives promise), if it succeeds I have to forward a success action, if it fails than an error action. The Observable itself shall keep going. For all I could search, RxJS do not have a mechanism for this catching the error and retrying the original. I have following solution in my code which I am not happy with: error$ = new Rx.Subject(); searchResultAction$ = search$

http request every x seconds in angular

依然范特西╮ 提交于 2019-12-05 21:41:54
I'm trying to refresh an http call every x seconds in angular2. ionViewDidLoad() { let loader = this.LoadingController.create({ 'content':'Please Wait' }); loader.present().then(()=>{ this.http.request('http://mywebserver.com/apps/random.php').map(res=> res.json()).subscribe(data=>{ console.log(JSON.stringify(data)); loader.dismiss(); this.fact = data; },err=>{ loader.dismiss(); let alert = this.alertCtrl.create({ title: 'Error!', subTitle: 'Please check your Internet Connectivity', buttons: ['OK'] }); alert.present(); }) }) } I get data when the page newly loads. But now my issue is

Is there a way to create an observable sequence triggered by method calls without using Subject?

♀尐吖头ヾ 提交于 2019-12-05 21:18:48
I have a service with a couple of methods, called in various different places in my code. class Service { method1() { } method2() { } I'd like to be able to subscribe to those method calls, ie have an observable which emits a value whenever one of those methods is called. I realize I can do this with an Rx.Subject but I'm wondering if there's a way to do it without, because my case doesn't satisfy the requirements listed here ie I don't need a hot observable. Use a subject. Your desired observable is, by definition, hot. Read through the Hot and Cold Observables article again. Here's the

Easiest way to unsubscribe subscriptions Angular

跟風遠走 提交于 2019-12-05 20:48:01
Hi am very new to Angular. I have around 4 database queries and each of them are Subscriptions(rxjs/Rx) . So I know I need to unsubscribe each of my subscriptions to save memory leakage. How can I optimise the calling? I mean, I don't want to call each subscription and unsubscribe one by one. I wanna do it all the unsubscribe in one call. Sorry if its a stupid question. Any idea guys? Thanks in advance Günter Zöchbauer subscriptions = Subscription[]; someMethod() { this.subscriptions.push(http.get(...).map(...).subscribe(...)); } ngOnDestroy() { this.subscriptions.forEach(s => s.unsubscribe())