rxjs

Debounce without initial delay

跟風遠走 提交于 2019-12-07 02:39:21
问题 Is there an operator in RxJS that debounces without delaying the "first event in a burst", but delaying (and always emitting) the "last event in a burst"? Something like this: ---a----b-c-d-----e-f--- after awesome-debounce(2 dashes) becomes: ---a----b------d--e----f while a normal debounce would be: -----a---------d-------f It's kind of a mix between throttle and debounce... 回答1: Hmmm, this is the easiest solution I can think of. The interesting part for you is the awesomeDebounce() function

How to implement intervals/polling in angular2 to work with protractor?

这一生的挚爱 提交于 2019-12-07 01:45:20
问题 I have an angular2 app I want to test with protractor. In this app I have a page with a graph that is being updated in regular intervals with autogenerated data. Apparently one feature of protractor is waiting for scripts and http calls to finish before executing test code. However, if there is a constantly polling script that never finishes, protractor will wait forever and time out after a certain time. In angular1 this could be solved by implementing the polling with $interval , which

RxJS publishReplay vs publishLast

强颜欢笑 提交于 2019-12-07 01:35:47
问题 I am implementing caching HTTP results in Angular application. From what I know both of the following code works, but I need to know if they are doing exactly the same thing, or I am missing something important? publishLast getPosts() { if( !this.posts$ ) { this.posts$ = this.http.get('api').publishLast().refCount(); return this.posts$; } return this.posts$; } publishReplay getPosts() { if( !this.posts$ ) { this.posts$ = this.http.get('api').publishReplay(1).refCount(); return this.posts$; }

Angular2 RxJS calling class function from map function

情到浓时终转凉″ 提交于 2019-12-07 01:21:37
问题 I'm new to Angular 2 and Observables so I apologise if my problem is trivial. Anyway I'm trying to test the Angular 2 HTTP Client using RxJS. Although I got it to work I need to add more logic to the service I'm currently working on. Basically I'd like to have a mapping function to convert the object I receive from the web service I'm connected to, to the model object I have in Angular. This is the code that works: import { Injectable } from 'angular2/core'; import { Http, Response } from

Does my “zipLatest” operator already exist?

三世轮回 提交于 2019-12-06 23:52:14
问题 quick question about an operator I've written for myself. Please excuse my poor-man's marble diagrams: zip aa--bb--cc--dd--ee--ff--------gg --11----22--33--------44--55---- ================================ --a1----b2--c3--------d4--e5---- combineLatest aa--bb--cc--dd--ee--ff--------gg --11----22--33--------44--55---- ================================ --a1b1--c2--d3--e3--f3f4--f5--g5 zipLatest aa--bb--cc--dd--ee--ff--------gg --11----22--33--------44--55---- ================================ -

RxJs and Typescript. TS2307: Cannot find module '@reactivex/rxjs'

两盒软妹~` 提交于 2019-12-06 22:37:08
问题 I got a problem with typescript and RxJs v5. Please Look the UPDATE sections. I did yarn add @reactivex/rxjs (also yarn add rxjs ) and on my index.ts did import Rx from '@reactivex/rxjs'; and got this error: Also, if I run node ./node_modules/.bin/tsc I got this error back too error TS2307: Cannot find module '@reactivex/rxjs'. UPDATE Also doing import { Observable } from 'rxjs/Observable' throws the same error . UPDATE 2 Well this seems to be more related to TS itself than to RxJS.

TypeError: rxjs__WEBPACK_IMPORTED_MODULE_2__.Observable.throw is not a function

给你一囗甜甜゛ 提交于 2019-12-06 22:27:35
问题 Here is my file userdata.service.ts : import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http'; import {Observable} from 'rxjs'; import { map } from "rxjs/operators"; import { catchError } from 'rxjs/operators'; import { Data } from './userdata'; @Injectable() export class UserDataService { url : "http://localhost:4200/assets/data/userdata.json"; constructor(private http:Http) { } getDataWithObservable() : Observable<any>{ return this.http.get(this.url) .pipe

RxJS Observable: Subscription lost?

微笑、不失礼 提交于 2019-12-06 22:19:05
问题 What is the difference between the following two observable mappings? (if something in the following code appears strange to you: it stems from a learning-by-doing hobby project; I still learn RxJS) I have a component with a getter and a constructor. Both read information from the app's ngrx store and extract a string ( name ). The only difference between the getter and the constructor: the getter is used in the HTML and the observable it returns is sent through an async pipe, whereas the

How to “react” on data changes with RxJS?

情到浓时终转凉″ 提交于 2019-12-06 20:19:05
问题 RxJS beginner here: I have problems with saving and tracking data changes using RxJS. Say I structure my app in small views/widgets and every view/widget has its own state and should do things on data changes. How do I do that? More concrete example. Let's say I have a widget called Widget and Widget has a title and button. The state should contain the title and the information if the button was already clicked. From reading the docs of RxJS it seems this would be a good starting point: var

How to Map Response object returned by Http Service to a TypeScript Objects using Observable Map function in Angular2

*爱你&永不变心* 提交于 2019-12-06 20:07:24
问题 Hi I have created an angular2 service whose task is to call a webapi which returns data in a json object structure as follows: //Result of the webapi service call. { "Total":11, "Data":[{"Id":1,"Name":"A","StartDate":"2016-01-01T00:00:00"}, {"Id":2,"Name":"B","StartDate":"2016-02-01T00:00:00"}] } Here is my angular2 service. The getMileStones methods work perfectly and I am able to cast the response back to MileStone[] . But In order to get the paged data I have created a function