rxjs

Why we should use RxJs of() function?

[亡魂溺海] 提交于 2020-01-09 07:13:11
问题 in service section of angular.io tutorial for angular2 I hit a method named of.for example : getHeroes(): Observable<Hero[]> { return of(HEROES); } or in below sample: getHero(id: number): Observable<Hero> { // Todo: send the message _after_ fetching the hero this.messageService.add(`HeroService: fetched hero id=${id}`); return of(HEROES.find(hero => hero.id === id)); } in angular.io Just explained used RxJS of() to return an Observable of mock heroes (Observable). and It was not explained

Observable Finally on Subscribe

穿精又带淫゛_ 提交于 2020-01-09 06:09:21
问题 According to this artcle, onComplete and onError function of the subscribe are mutually exclusive. Meaning either onError or onComplete events will fire up in my subscribe . I have a logic block which needs to be executed whether I receive an error, or I finish my steam of information successfully. I looked up for something like finally in python, but all I found is finally which needs to be attached to the observable I create. But I want to to do that logic only when I subscribe, and after

How to make an RxJS subscription with an async function serialize the onNext calls?

旧时模样 提交于 2020-01-07 09:26:15
问题 This is a followup for this question. So RxJS is calling my async function with the next event bebore the previous one has completed as soon as I await in my async method. I need to serialize the calls to this async function. I have understood from this answer to a similar question that I need to move my async function away from subscribe and use concatMap. Right now my code does not compile with the following error: error TS2339: Property 'concatMap' does not exist on type 'Observable'. My

Wait for latest values from dependent streams in BaconJS?

帅比萌擦擦* 提交于 2020-01-07 02:49:04
问题 I have 3 streams. gradingResult and contextId depend on studentResponse . I need to fire an event and only one event (otherwise, this is trivial) when all 3 have the latest values. I've tried #combineTemplate and #sampledBy studentResponse . Unfortunately, I always see the wrong data--- gradingResult and contextId have the old values in the combined template. How can I wait for all streams to have the latest values? Code is shown below: var studentResponse = new Bacon.Bus(); var gradingResult

simulating two observables emiting successively

一世执手 提交于 2020-01-07 00:54:19
问题 I have a component that has two properties that are observables @Component({ }) export class MyComponent { observable1$; observable1$; ngOnInit() { Observable1$ = this.service.getObservable1(); Observable2$ = this.service.getObservable2(); } } I practice, observable2$ will emit bar only after observable1$ emits foo . How can I write a test that simulates this? If I write in my spec mockService.getObservable1.and.returnValue(Observable.of('foo')) mockService.getObservable2.and.returnValue

Angular 2 *ngFor and form submit ceased working when moved to observables

安稳与你 提交于 2020-01-06 19:47:07
问题 I had an app initiating course components like this: <li *ngFor="let course of courses"> <app-course [appCourse]="course" (remove)="removeItem($event)" ></app-course> </li> from an array pulled from local storage, which was populated from a course form, sending an object like this: { "_id": "587f52ad266c32fbfb10f21a", "end": "31/1/2017", "start": "1/1/2017", "desc": "see title", "name": "Intro To Express", "id": 1, "__v": 0, "updated_at": "2017-01-18T11:34:05.416Z" } Then I added a back end

How to listen to Firebase update and trigger effect/store side effect to update the Store state?

两盒软妹~` 提交于 2020-01-06 17:59:30
问题 I am very confused on integrating Firebase with ngrx/store. Since Firebase has socket based "live" update, so the store data is already sync with Firebase data whenever I update Firebase. The problem is, I do not know how to listen to Firebase update and trigger a side effect with effect/store to do some more update on Firebase and the client store. Any suggestion on how should I approach this problem. For now, I have to use a long pull Observable.interval(5000) strategy to trigger a service

How to listen to Firebase update and trigger effect/store side effect to update the Store state?

不羁的心 提交于 2020-01-06 17:59:21
问题 I am very confused on integrating Firebase with ngrx/store. Since Firebase has socket based "live" update, so the store data is already sync with Firebase data whenever I update Firebase. The problem is, I do not know how to listen to Firebase update and trigger a side effect with effect/store to do some more update on Firebase and the client store. Any suggestion on how should I approach this problem. For now, I have to use a long pull Observable.interval(5000) strategy to trigger a service

How to listen to Firebase update and trigger effect/store side effect to update the Store state?

Deadly 提交于 2020-01-06 17:58:59
问题 I am very confused on integrating Firebase with ngrx/store. Since Firebase has socket based "live" update, so the store data is already sync with Firebase data whenever I update Firebase. The problem is, I do not know how to listen to Firebase update and trigger a side effect with effect/store to do some more update on Firebase and the client store. Any suggestion on how should I approach this problem. For now, I have to use a long pull Observable.interval(5000) strategy to trigger a service

full calendar - passing event data from observable - not showing up on calendar

回眸只為那壹抹淺笑 提交于 2020-01-06 08:33:49
问题 I am using ap-fullcalendar for angular/typescript. I have a data service, where I get the events for the calendar from my database, I wrap the data in a Behaviour Subject and subscribe to it and make it into an observable from another function. I have a data service because I have multiple subscriptions to the same observable. In my component where the calendar is, I subscribe to the data. However, for some reason, the events are not getting passed properly to the calendar and won't show up.