rxjs

Subscriber should not stop on error in observable

亡梦爱人 提交于 2020-01-04 03:52:06
问题 I am struggling with a subscriber, which automatically unsubscribe itself on error: observable .subscribe( (data) => { // some logic encountering an error during execution // comparable to throw new Error() } ) I can prevent it with using try / catch: observable .subscribe( (data) => try { // some logic encountering an error during execution // comparable to throw new Error() } catch(e) { } ) But it feels like a work around. I have dived into the source of Subscriber and SafeSubscriber, which

Return Observable inside the Promise

喜欢而已 提交于 2020-01-04 03:44:48
问题 Could you tell me how can I return Observable here? I have tried many ways. But no success yet. [ts] A function whose declared type is neither 'void' nor 'any' must return a value. deleteInvite(inviteId):Observable<HttpResponse<Object>> { this.getHttpHeader().then(headers => { return this.http.post(this.apiURL + "/deleteInvite", inviteId, { observe: "response", headers: headers }) }).catch(err => { console.error(err); }); } async getHttpHeader() { const accessToken = await this.getJWTToken();

How do I timeout an event in RxJS?

五迷三道 提交于 2020-01-04 01:57:10
问题 I'm trying to detect if the mousedown event is held for a period of time before a mouseup . I'm using timeout() on an Observable created with fromEvent() to do so, but the timeout returns both Observables. Below, subscribing to stream returns the event if mousedown is triggered within 1 second, but it also returns 1. var mousedown = Rx.Observable.fromEvent(target, 'mousedown'); var stream = mousedown.timeout(1000, Rx.Observable.return(1)); var sub = stream.subscribe( function (x) { console

Read buffered response with Angular2/RxJS

牧云@^-^@ 提交于 2020-01-03 19:59:59
问题 I'm building a website that reads data from a backend. That data is computed on-the-fly and sent back to the client in a buffered manner. I.e. as soon as the first chunk is computed it is sent to the client, then it computes the next chunk and sends that to the client. This whole process happens in the same HTTP request. The client should not wait for the complete response to finish but handle each chunk by its own as soon as has been sent. Such responses can usually be consumed using the XHR

Read buffered response with Angular2/RxJS

倾然丶 夕夏残阳落幕 提交于 2020-01-03 19:59:50
问题 I'm building a website that reads data from a backend. That data is computed on-the-fly and sent back to the client in a buffered manner. I.e. as soon as the first chunk is computed it is sent to the client, then it computes the next chunk and sends that to the client. This whole process happens in the same HTTP request. The client should not wait for the complete response to finish but handle each chunk by its own as soon as has been sent. Such responses can usually be consumed using the XHR

Observable: Why result not in subscribe() success function if preceded by map()?

梦想与她 提交于 2020-01-03 16:50:59
问题 I refer to this post which was really helpful to understand Observables, but there is still something I don't get. In the plunker it refers to, I changed the "src/myfreinds.ts" to see a bit what happen and added some console log: First I left it as the same: export class FriendsList{ result:Array<Object>; constructor(http: Http) { console.log("Friends are being called"); http.get('friends.json') .map(response => { console.log("map"); console.info(response); response.json(); //MISTAKE WAS HERE

ngrx polling to refresh data when subscribed

一曲冷凌霜 提交于 2020-01-03 16:49:29
问题 Context I am using the following libraries in the relevant application: Angular 4.x, ngrx 4.x, rxjs 5.4.x In my application I am able to get some data from a websocket but for some I have to hit a RESTful api. I am sharing the data between multiple components through ngrx. Right now I refetch the data based on events like create, update, and delete. I don't expect much concurrent modification of the data but I do need a way to manually or automatically ensure that my client state matches the

ngrx polling to refresh data when subscribed

做~自己de王妃 提交于 2020-01-03 16:49:12
问题 Context I am using the following libraries in the relevant application: Angular 4.x, ngrx 4.x, rxjs 5.4.x In my application I am able to get some data from a websocket but for some I have to hit a RESTful api. I am sharing the data between multiple components through ngrx. Right now I refetch the data based on events like create, update, and delete. I don't expect much concurrent modification of the data but I do need a way to manually or automatically ensure that my client state matches the

Angular 2 - RxJS Switch Map Issue

女生的网名这么多〃 提交于 2020-01-03 13:35:29
问题 I'm trying to have an infinite scrolling section in my application. To achieve this I'm using this component to handle the scroll events and so on. When the scroll reaches the bottom of the div I'm calling a function to get more data. So far so good. To make this function more efficient I'm trying to wait a few seconds before the call is made as well as make sure that the data is processed properly. To do this I've been looking at the example shown on the Angular website that showcases a

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

孤人 提交于 2020-01-03 09:49:59
问题 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(