rxjs5

How do I - Long polling and Schedulers?

大城市里の小女人 提交于 2020-01-21 10:01:28
问题 I am trying to schedule a long polling mechanism. And I was wondering if I could leverage Schedulers for that. Here's what I have been thinking so far. Schedule via timer, but only enqueue next iteration if previous iteration has already finished. Enqueue next iteration as previous iteration is finishing. I have been looking at existing schedulers, but I am not really sure which one to pick and what to overload. And last but not least - as I am a novice in Rx world - what are the advantages

How to periodically check live connection using rxjs?

江枫思渺然 提交于 2020-01-15 09:52:21
问题 I use rxjs to handle a websocket connection var socket = Rx.Observable.webSocket('wss://echo.websocket.org') socket.resultSelector = (e) => e.data I want to periodically (5s) sent a ping message and wait 3s to receive a pong response and subscribe to the a stream if no response has been receive. I try that without success. I admit I'm a bit lost will all the operator available to handle timeout, deboune or throttle. // periodically send a ping message const ping$ = Rx.Observable.interval(2000

How to periodically check live connection using rxjs?

冷暖自知 提交于 2020-01-15 09:52:10
问题 I use rxjs to handle a websocket connection var socket = Rx.Observable.webSocket('wss://echo.websocket.org') socket.resultSelector = (e) => e.data I want to periodically (5s) sent a ping message and wait 3s to receive a pong response and subscribe to the a stream if no response has been receive. I try that without success. I admit I'm a bit lost will all the operator available to handle timeout, deboune or throttle. // periodically send a ping message const ping$ = Rx.Observable.interval(2000

RxJS (5.0rc4): Pause and resume an interval timer

旧时模样 提交于 2020-01-14 12:10:44
问题 I am using Rx to keep an animation clock. Every animation frame, it maps an interval tick to the new values for that tick. Suppose I want to pause the animation. The most natural way would be to somehow suspend the clock rx and then resume it at a later time. Unsubscribe then resubscribe isn't a natural fit, because this animation clock is a cold observable. I don't want to restart the animation when they resume. If I go for a workaround method, I will have to generate a new resume rx, vastly

RxJS (5.0rc4): Pause and resume an interval timer

江枫思渺然 提交于 2020-01-14 12:10:35
问题 I am using Rx to keep an animation clock. Every animation frame, it maps an interval tick to the new values for that tick. Suppose I want to pause the animation. The most natural way would be to somehow suspend the clock rx and then resume it at a later time. Unsubscribe then resubscribe isn't a natural fit, because this animation clock is a cold observable. I don't want to restart the animation when they resume. If I go for a workaround method, I will have to generate a new resume rx, vastly

RxJS (5.0rc4): Pause and resume an interval timer

元气小坏坏 提交于 2020-01-14 12:08:24
问题 I am using Rx to keep an animation clock. Every animation frame, it maps an interval tick to the new values for that tick. Suppose I want to pause the animation. The most natural way would be to somehow suspend the clock rx and then resume it at a later time. Unsubscribe then resubscribe isn't a natural fit, because this animation clock is a cold observable. I don't want to restart the animation when they resume. If I go for a workaround method, I will have to generate a new resume rx, vastly

RxJs: Incrementally push stream of data to BehaviorSubject<[]>

北城余情 提交于 2020-01-13 07:56:30
问题 Basically I'm trying to inflate BehaviorSubject<[]> with array of data which will be loaded in chunks. BehaviorSubject<[]> will be added with new chunk of data (like Array.push ) but I don't want to use another array to store and add to BehaviorSubject.next because this will cause rendering to take too long as the data grow over time. Any suggestion? 回答1: You can use getValue() method to achieve what you want to do. Example: data = new BehaviorSubject<any[]>([]); addData(foo:any):void{ // I'm

Observable Finally on Subscribe

穿精又带淫゛_ 提交于 2020-01-09 06:09:21
问题 According to this artcle, onComplete and onError function of the subscribe are mutually exclusive. Meaning either onError or onComplete events will fire up in my subscribe . I have a logic block which needs to be executed whether I receive an error, or I finish my steam of information successfully. I looked up for something like finally in python, but all I found is finally which needs to be attached to the observable I create. But I want to to do that logic only when I subscribe, and after

TypeError: unknown type returned

a 夏天 提交于 2020-01-07 01:55:47
问题 I am using ngrx/effects . I got this error: ORIGINAL EXCEPTION: TypeError: unknown type returned This is part of my codes: this.store.dispatch({ type: CHAT_LOAD_MESSAGES, payload: chatId }); @Effect() loadMessages$ = this.updates$ .whenAction(CHAT_LOAD_MESSAGES) .map<string>(toPayload) .do(chatId => console.log('chatId', chatId)) // Here I can get chatId .switchMapTo(chatId => this.chatService.loadMessages(chatId)) // The error comes out because of this line .do(res => console.log('res', res)

How to handle async function in redux-observable?

。_饼干妹妹 提交于 2020-01-05 09:04:37
问题 I am using RxJS and redux-observable. I am trying to read file in epic. In my case, I have to do it in epic, because some other epic trigger this epic multiple "unknown" times by expand operator. But since FileReader is async, the code below does not work. What is the correct way especially RxJS way to handle this? Thanks export const uploadAttachmentEpic = (action$, store) => action$ .ofType(UPLOAD_ATTACHMENT) .map(action => { const reader = new FileReader(); reader.onload = () => { return {