rxjs

Safe update for 2 dependent streams

与世无争的帅哥 提交于 2019-12-11 10:16:55
问题 As an exercise I'm trying to build 2 dependent streams which update one another. The test application is simply an "Inches <-> Centimeters" converter, with both inputs editable. The issue I am experiencing is that I cannot get how can I stop recursion that causes one field change. To better explain the issue let's have a look at the relevant part of code: var cmValue = new Rx.BehaviorSubject(0), inValue = new Rx.BehaviorSubject(0); # handler #1 cmValue.distinctUntilChanged().subscribe

Subscribing to a simple request is the right approach on Angular 2 in this case?

断了今生、忘了曾经 提交于 2019-12-11 10:09:33
问题 I have a Parking System that I use Angular 6 + Laravel for the backend, I have a post that I post some of my problems that were resolved by the DigitalDrifter thank you. Here is the link: How to Make a Scheduler Task for Every New Record After 20 Minutes in Laravel? My system is not 100% good because I having a strange behaviour. Every client must go to the Payment Area and validated your entry. When the client show the ticket to the cashier he validated the entry after the payment clicking

Combining 2 arrays in correct sequence using Rx.js

China☆狼群 提交于 2019-12-11 09:52:04
问题 I am a bit new Rx.js and trying to get this scenario working.Basically I need combine the following two sequences such that they merge into a single array, where the obs1 elements are always before obs2 elements, var obs1 = Rx.Observable.create(function(observer){ setTimeout(function(){ observer.next([1,2,3]); }, 1000); }); var obs2 = Rx.Observable.create(function(observer){ setTimeout(function(){ observer.next([4,5,6]); }, 10); }); I am not going "complete" any of these observables by the

Angular 2 - Creating form in a subscription causes crash saying the formGroup is undefined

心已入冬 提交于 2019-12-11 09:23:29
问题 I've got some data in my Firebase database, this data I want to apply to a form via FormBuilder . It works somewhat good but I get errors more often than not saying formGroup expects a FormGroup instance. Please pass one in. . What doesn't make sense is that when I apply new changes to the database which cause the subscription to fire, I get the error. Despite this.settingsForm being set before and after the subscription runs after updating. Here's the subscription: this.eventSubscription =

How to unsubscribe or dispose an interval observable on condition in Angular2 or RxJS?

拈花ヽ惹草 提交于 2019-12-11 08:56:10
问题 I'm new to the whole Rx thing and reactive programming, however I have to deal with such a situation. I want a interval observable to check a hardware's status by a POST request to its REST API every 500ms to see if the response changes. So once it changes, I want such interval observable POST request shut down immediately, leaving resource to other future operations. Here is a piece of code. myLoop(item_array:number[], otheroption : string){ for (let item of item_array){ //set hardware

Observable concat method on array returns the same array

為{幸葍}努か 提交于 2019-12-11 08:49:26
问题 In my service I try to solve the next problem. I have a json file with the names of other json files (cards): { "filename1" : ... , "filename2" : ... , ... "filenameN" : ... } I need to load all that files. "filenameX" files have some card data : { dataX } I need to combine loaded data in object: { "filename1" : { data1 }, "filename2" : { data2 }, ... "filenameN" : { dataN } } I create Observer for any file loading and try to combine them to a high-level single Observer which is resolved when

Rxjs - Mapping from json to typescript interface

泄露秘密 提交于 2019-12-11 08:47:55
问题 So, as I've been exploring this new space I needed to do a Web API call. Theres a lot of confusion out there between the versions of everything. Anyhow, I found something that works, and I know "best practice" is a bit too subjective. However, what I don't know is if there is a more direct way to do this. Here is the format of the response I'm seeking: export interface AuditDetail { updatedAt: Date; updatedBy: string; } Here is the server-side model: [DataContract] public class PlanHistory {

Async pipe to unsubscribe from ReplaySubject

纵饮孤独 提交于 2019-12-11 08:37:04
问题 I have the following service to accommodate for a global spinner in my app: import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { ReplaySubject } from 'rxjs/ReplaySubject'; @Injectable() export class SpinnerService { private visible = new ReplaySubject < boolean > (); showSpinner() { this.visible.next(true); } hideSpinner() { this.visible.next(false); } getSpinnerVisibility(): Observable < boolean > { return this.visible.asObservable(); } } Then

Angular2 carry over value of variable when changing pages

不想你离开。 提交于 2019-12-11 08:21:46
问题 I have a multi-page website (using the router) and would like to carry a variable value over from one page to the other. On my contact form page, I have the following code: testName:string = "hello"; ngOnInit() { this.dataService.Stream .subscribe( (city:City) => this.processData(city), (err) => console.log('Error at processing data'), () => console.log('Complete...') ) } processData(city:City) { console.log('the city name is: ', this.testName); this.problematicCity = city; this.testName =

Angular observable behavior odd when shared

房东的猫 提交于 2019-12-11 08:12:54
问题 I have an observable that when I use the rxjs 'share' operator behaves strangely in the Angular template. Here's how I setup my two observables (in a service): this.family = this.store.select(getFamily).pipe( tap(family => { if (family == null) { this.loadFamily(); } }), filter(family => family != null), share(), ); this.familyMembers = this.family.pipe( map(family => { return family.familyMembers; }) ); I then add the familyMember observable to my component as a property this.familyMembers =