rxjs

RxJS operator that waits for quiet period in event stream, but in case of busy event stream does not wait for ever

帅比萌擦擦* 提交于 2019-12-22 10:50:56
问题 The scenario: I have a stream of events, each event should result in the updated display of information (event stream is from websockets and the display is in a highcharts chart, but that is not important) For performance reasons, I do not want to trigger a UI update for each event. I would rather do the following: When I receive an event I want to do the UI update only it is more than X milliseconds since the last update But every Y milliseconds (Y > X) I want to do an update anyway, if

Functional reactive operator for custom filter based on another Observable

北慕城南 提交于 2019-12-22 10:28:58
问题 For fun and to learn I'm trying to implement an undo system in my app using functional reactive programming. I have a stream of state changes, which need to be saved onto the undo stack. When the user clicks undo, I take a value from the stack and update application state accordingly. The problem is that this update itself also generates an event in the state change stream. So what I would like is to derive another stream from state changes, which ommits state change right after undo. A

Conditional emission delays with rxjs

删除回忆录丶 提交于 2019-12-22 09:56:37
问题 From picture to code? How to get the Out observable from Data and Gates? Data is an observable of any kind e.g. JSON objects to be sent to a remote backend Gates is a boolean observable, where the ticks correspond to true and the crosses to false. For example, Internet connectivity whereby true means the network became accessible and false reflects a disconnection. Out is the resulting observable, which emits the same as Data, sometimes immediately, sometimes with a delay, depending on the

Lazy loading : Observable not subscribed

北战南征 提交于 2019-12-22 09:23:22
问题 In my Angular App, I have a parent component : console.component.html <div class="main"> <ibe-snackbar></ibe-snackbar> <router-outlet></router-outlet> </div> routler-outlet can load two child component. One is loaded eagerly the other one is loaded with lazy loading. Here's the routes file console.component.routes const ConsoleRoutes: Routes = [ { path: 'console', component: ConsoleComponent, data: {context : CONSOLE_CONTEXT}, children: [ { path: "projects", component: ProjectsListComponent,

ng-bootstrap typeahead: how to handle Observable<Person[]> rather than Observable<string[]>

假装没事ソ 提交于 2019-12-22 08:57:44
问题 I've a newbie Angular/Typescript question. I followed the Wikipedia example defined in ng-bootstrap typeahead and I decided to replace the Wikipedia call with a custom REST service that provides the following GET call: GET /person/name/{name} and returns a list of persons matching the name, where each person is: Person(id:long, name:string, surname:string) Now from the typescript part and the angular part everything works fine if I map(...) the array of persons to an array of string of names

What is the difference between throttleTime vs debounceTime in rxjs and when to choose which?

会有一股神秘感。 提交于 2019-12-22 08:51:35
问题 I'm trying to understand throttleTime vs debounceTime and which one is to be used when? I have an upvote button that makes an API request to the backend (which counts the votes). User can submit button multiple times, but I'd like to limit the times per second button can be pressed. I know throttleTime and debounceTime operators can do that, but which should I choose better? const upvoteClicks = fromEvent(this.el.nativeElement, 'click') .pipe(debounceTime(500)) .subscribe(() => this.myService

RxJs difference between complete and unsubscribe in Observable?

*爱你&永不变心* 提交于 2019-12-22 08:30:01
问题 after complete event will unsubscribe Observable or not or any other difference. 回答1: You complete an Observable , and unsubscribe a Subscription . These are two different methods on two different objects. You subscribe to an observable which returns a Subscription object. If you want to stop listening to emits from the Observable you call subscription.unsubscribe() . If you want an Observable to be done with his task, you call observable.complete() . (this only exists on Subject and those

Observable closed on error

蓝咒 提交于 2019-12-22 08:23:15
问题 I have an issue with Observable in Angular 2. I subscribe my component to an observable, then when my service has new value, my component is notified. Problem is when the observer push an error, like an HTTP error, my observable is closed, so my component is no more notified. Question How can I do to make my component continue listening my service even when I have an error ? Example Here an example Here my code : Component constructor(private appService: AppService) { //I subscribe my

Angular2 observable http get conditional repeat

爷,独闯天下 提交于 2019-12-22 08:22:41
问题 I'm using angular2 observable pattern to make http requests. I'm trying to conditional repeat the http get: I want to execute the http get until a condition is met: http.get('url') .map(res => { // if the condition is met I should repeat the http get request }) .subscribe() Is there a way to conditional repeat the http get request? Thanks, Marco 回答1: You can use expand operator. Here's an example: let request$ = http.get('url'); request$.expand(value => { return value !== 0 ? request$ : Rx

Dispatch an action in response to cancellation

。_饼干妹妹 提交于 2019-12-22 08:06:33
问题 I started with the cancellation recipe from the redux-observable docs and want to extend it a bit. Basically I have a scenario where after the cancellation is triggered, using takeUntil I want dispatch another action to cleanup, etc. This is what I came up with so far: https://jsbin.com/zemenu/195/edit?js,output Start a "Fetch User Info" and then hit Cancel. I want it to execute actions in this order: - USER/FETCH - REQUEST/STARTED - USER/CANCELLED - REQUEST/CANCELLED This works in the way I