rxjs

How to handle mouse and touch events simultaneously with reactive event streams

前提是你 提交于 2020-01-03 09:49:09
问题 I'm building an audio playback control that lets users scrub back and forth through an audio file. It needs to work with touch and mouse events. How should I go about managing the events for this with reactive event streams? Here's a rough idea of how I would expect to build it. <div id="timeline"> <span id="scrubber"></span> </div> then, using Bacon.js to create event streams var mousedowns = $('#timeline').asEventStream('mousedown'); var touchstarts = $('#timeline').asEventStream(

How to find an element of an array by id with Observable in Angular2

早过忘川 提交于 2020-01-03 06:58:13
问题 I decided to use Observable instead of Http promises. That is how my Promise service looked: export class MovieService { movies: Movie[] movie: Movie; constructor(private http:Http) { } getMovies(): Promise<Movie[]>{ return this.http.get('http://api.request.com') .toPromise() .then((res:Response) => res.json()['results']) } getMovie(id: number): Promise<Movie> { return this.getMovies() .then(movies => movies.find(movie => movie.id == id)); } } First I fetch an array of movies, and than I find

Angular2 + RxJS nested HTTP calls

为君一笑 提交于 2020-01-03 02:50:11
问题 Good morning to everyone. I'm a newbie of Angular2 and in a project I'm working on I have to make some HTTP requests in order to retrieve data from a REST backend. From the backend I have to get a list of Modules. Each Module has one or more Actions. The typescript classes representing the two entities are the following export class Module { public name: string; public htmlPath: string; public actions: ModuleAction[]; constructor(data: IModule){ this.name = data.name; this.actions = []; this

User notification service with rxjs in Angular?

半腔热情 提交于 2020-01-03 02:46:08
问题 I'm relatively new to reactive programming and I'm trying to create an Angular service which can display notifications to the user. So far this is what I have: https://stackblitz.com/edit/angular-rxjs-notifications?file=app%2Fapp.component.html But there is a major problem with my implementation that I don't know how to solve: How, in a reactive way, can I queue up notifications? I would like my notification div to appear when the first notification is pushed and when the user clicks "Clear"

Angular - Catching error after all HTTP retry failed

此生再无相见时 提交于 2020-01-03 02:04:30
问题 I am using Angular Service to get data from my API . I implemented retry feature in case of fetching data fails. Now i need to handle the error when all the retries wear out, but im not able to catch it. Following is my code, public getInfoAPI(category:string, id:string = "", page:string = "1", limit:string = "10"){ var callURL : string = ''; if(!!id.trim() && !isNaN(+id)) callURL = this.apiUrl+'/info/'+category+'/'+id; else callURL = this.apiUrl+'/info/'+category; return this.http.get

Memoize for Observables in Typescript

烈酒焚心 提交于 2020-01-02 12:09:34
问题 I am looking for the best way of implementing an optimization for very expensive method that takes multiple parameters and returns an Observable. Is there an elegant way of doing it? What I am looking for is prettier version of this: class Example { constructor( private databaseService: DatabaseService, private someService: SomeService) expensive(param1: string, param2: string) : Observable<string> { if (isMemoraized(param1,param2) { return Observable.create(observer=> observer.next

Rate-limiting and count-limiting events in RxJS v5, but also allowing pass-through

烈酒焚心 提交于 2020-01-02 11:19:14
问题 I have a bunch of events to send up to a service. But the requests are rate limited and each request has a count limit: 1 request per second: bufferTime(1000) 100 event items per request: bufferCount(100) The problem is, I am not sure how to combine them in a way that makes sense. Allowing pass-through Complicating this further, I need to make sure that events go through instantaneously if we don't hit either limit. For example, I don't want it to actually wait for 100 event items before

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

时光毁灭记忆、已成空白 提交于 2020-01-02 07:49:35
问题 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. 回答1: Use a subject. Your desired

New to RxJS, range is not a function

点点圈 提交于 2020-01-02 05:41:11
问题 I'm trying to create a simple TypeScript file to use RxJS. Here is what I did: " npm install rxjs ", referenced " traceur & systemjs " in my " index.html " and created a " test.ts " file with this: import {Observable} from 'rxjs/Rx'; Observable.range(1, 2, 3, 4, 5) .map(x => x * 2) .filter(x => x > 5) .subscribe( x => console.log(x), err => console.log('Error'), ok => console.log('No error') ); I'm configuring systemjs like this: System.config({ defaultJSExtensions: true, map: { 'rxjs': 'node

Angular2. Map http response to concrete object instance

梦想的初衷 提交于 2020-01-02 04:46:08
问题 Сommon approach to process http response is like that: return this._http.get(url) .map((res: Response) => res.json()); which provides you with an Observable<Object[]> where Object is dynamically created type from json de-serialization. Then you can use this result in *ngFor="let item of result | async" etc... I'd like to get a specific type instance (meaning using new operator to call the type's constructor). Tried different ways to achieve something like that: .map((res: Response) => { let