rxjs

Angular 2 / RXJS - need some help batching requests

本小妞迷上赌 提交于 2019-12-06 11:12:53
I keep reading rxjs documentation but getting lost in all the operators.. this is what i got so far let obs = Observable.from([1, 3, 5]) so what i need this to do is take() some set amount from the array. use the results in a post request, when that comes out successful then i need to restart the process. I want to collect all the results, and keep progress as the process is going (for a progress bar) I don't need the code for all of that. what i really need to know is how to use rxjs to split this array up.. send part of it, and restart the process until theres nothing left to send. FINAL

How to share data between components using service and observable?

十年热恋 提交于 2019-12-06 11:12:29
Hi I am new to angular 2+, I am trying to share data between two components but the second component is not retrieving the data from the service, it gets an empty object. Service - using rxjs BehaviorSubject to keep the object import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { Observable } from 'rxjs/Observable'; @Injectable() export class PostsService { response: any = {}; private messageResponse = new BehaviorSubject(this.response); currentResponse = this.messageResponse.asObservable(); constructor(private http: Http) { } // Get all posts from the API getAllPosts() { return

Angular 2 Service + RxJS BehaviorSubject or EventEmitter

醉酒当歌 提交于 2019-12-06 11:01:16
I am new to Angular 2 and RXJS. I have a custom header component with 2 triggers (buttons) which should activate 2 different navigation directives in different parts of the application. I have created a service which registers the 2 different navigation directives and the header component subscribes to this. I wanted to know whats the best way to link the buttons in the header to call the open() and close() functions in each of the directives depending on the trigger that is clicked. NOTE: Please note that I cannot use ViewChild or ContentChild because the navigation can be anywhere on the

RxJS not all Subscribers receive all events

僤鯓⒐⒋嵵緔 提交于 2019-12-06 10:43:08
I'm working on an exercise about RxJS. And there's something very strange happening: typoStream.subscribe(x => console.log('wont get executed')); wordCompletedStream.subscribe(nextStream); typoStream.subscribe(x => console.log('will get executed')); When the application runs the first console.log won't get printed and the second one will. Regardless of what the streams are and how they interact - this should never happen, right? Why is it important when I subscribe to an observable - shouldn't it emit the event to every subscriber anyways? If you want to try it: http://embed.plnkr.co

How to buffer stream using fromWebSocket Subject

时间秒杀一切 提交于 2019-12-06 10:42:52
问题 This RxJava buffer example (with marble chart!) describes the desired result perfectly: collect items in buffers during the bursty periods and emit them at the end of each burst, by using the debounce operator to emit a buffer closing indicator to the buffer operator Edit: having reviewed How to create a RxJS buffer that groups elements in NodeJS but that does not rely on forever running interval?, my issue appears related to using a Subject as opposed to straight Observable . Using the

Recursive using expand() and concatMap() in Angular 7

前提是你 提交于 2019-12-06 09:49:03
问题 I have following API list below: 1. https://www.something.com/?filter=something Result: { id: 12 previous: null next: https://www.something.com/?filter=something&page=2 data: ... } 2. https://www.something.com/?filter=something&page=2 Result: { id: 13 previous: https://www.something.com/?filter=something next: https://www.something.com/?filter=something&page=3 data: ... } 3. https://www.something.com/?filter=something&page=3 Result: { id: 14 previous: https://www.something.com/?filter

Implementing fromSubscriber in rxjs

♀尐吖头ヾ 提交于 2019-12-06 08:43:06
问题 I ran into an interesting issue today. I'm working on an app where we have file uploads, and we want to implement a progress bar. The app is written using React/Redux/Redux-Observable. I want to dispatch actions for upload progress. Here's what I did to implement it: withProgress(method, url, body = {}, headers = {}) { const progressSubscriber = Subscriber.create(); return { Subscriber: progressSubscriber, Request: this.ajax({ url, method, body, headers, progressSubscriber }), }; } I have a

How to use retryWhen with a function that returns a Boolean?

三世轮回 提交于 2019-12-06 08:19:01
Here's my code: this._http.post(this._url_get + extension, '', { headers: headers }) .map(res => res['_body']) .retryWhen(errors => {return responseErrorProcess(errors)}) now I need to catch exceptions and pass them to my responseErrorProcess() which returns true if it needs to retry I could not figure out how to retrieve the exceptions from errors , this is how it looks: Subject_isScalar: falseclosed: falsehasError: falseisStopped: falseobservers: Array[0]thrownError: null__proto__: Observable` It doesn't seem to contain errors about the exceptions that occurs, plus I couldn't figure out what

Angular 4 losing subscription with router paramMap using switchMap

…衆ロ難τιáo~ 提交于 2019-12-06 08:11:14
问题 Using the latest version of Angular I have a very small, simple application - see below: The forecast detail component looks like the following: public getForecastData(forecastId) : Observable<any> { return this.http.get<any>('/api/forecasts/' + forecastId + '/data'); } ngOnInit() { this.route.paramMap .switchMap( params => { return this.getForecastData(params.get('id')) }) }) .subscribe( (data) => { // business logic here }); The issue I'm having is that if the getForecastData call fails

Angular service not working with http.get observable

佐手、 提交于 2019-12-06 07:30:31
I am trying to retrieve json file from the server using http.get and subscribe to the observable from a component. However, it's returning an error, not the data. Can you please tell me where I'm going wrong: import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; import { Observable } from 'rxjs'; @Injectable() export class MoviesService { constructor(private http: Http) { } getMovies() : Observable<any> { let url = API_URL; return this.http.get(url); } } and here's the component: import { Component } from '@angular/core'; import { MoviesService } from './movies