rxjs

RxJS and React's setState - delay function execution until subscription

狂风中的少年 提交于 2019-12-06 05:55:00
RxJS has a nifty function, fromCallback that takes a function whose last parameter is a callback and returns an Observable . And I want to combine that with React's setState function so that I can do something analogous to: const setState = Rx.Observable.fromCallback(this.setState); setState({ myState: 'Hi there!' }).concat(....) so that any operations chained to setState are guaranteed to happen after the state has been set and, most importantly, that setState isn't invoked until there's an active subscriber. What I noticed though is that even without a subscribe, setState is being called

Chained redux-observable epic only fires correctly once

拈花ヽ惹草 提交于 2019-12-06 05:54:11
I've set up an epic that waits for another epic to complete, much like @jayphelps' answer here: Invoking epics from within other epics However I've found that it only seems to run once. After that I can see the CART_CONFIG_READY action in the console but the DO_THE_NEXT_THING action is not triggered. I've tried various combinations of mergeMap and switchMap , with and without take but nothing seems to help. This is (kind of) what my code looks like. import { NgRedux } from '@angular-redux/store'; import { Observable } from 'rxjs/Observable'; import { ActionsObservable } from 'redux-observable'

How to use debounceTime but still trigger the function after certain time?

本小妞迷上赌 提交于 2019-12-06 05:52:47
问题 TLDR; I would like to use debounceTime to execute the function only if 300 milliseconds have passed without it being called. In the meanwhile, I also want to be able to trigger the function every 1 minutes If the process takes a long time. Otherwise, the function will only be triggered at the end of the process. Basically, our system has a long process that will fire a lot of SignalR update to the client. When I received the server command on the client, I will make 2 additional HTTP requests

Turn several ajax requests into Observables with RxJS

南笙酒味 提交于 2019-12-06 05:29:39
问题 I'm struggling with something - which I'm guessing means I've misunderstood and am doing something silly I have an observable and need to use it to create some object, send that to the server for processing, combine a result from the server with the object I sent, and then turn that into an observable so what I want to do (I think) is something like var theNewObservable = my.observable.things.select(function(thing) { var dataToSend = generateMyJavascriptObjectFrom(thing); var promise = $.ajax

Angular/rxjs/Subject/BehaviorSubject share http service data across multiple components

徘徊边缘 提交于 2019-12-06 05:20:19
Follow up question to Share data between components using a service in Angular2 and a response I got. I'm trying to share data that a service providers retrieves via a GET. The component structure is as follows with the main routes going to CustomerPortalDashboardComponent and DocumentsComponent <CustomerPortalBaseComponent> <router-outlet> <CustomerPortalDashboardComponent/> <DocumentsComponent/> <router-outlet> </CustomerPortalBaseComponent> CustomerPortalBaseComponent makes a call to get user info: ngOnInit() { this.customerPortalUserService.getUserInfo() .subscribe( (event: HttpEvent<any>)

How to use the 'flatmap' operator conditionally ? (Angular 2/rxjs)

眉间皱痕 提交于 2019-12-06 05:16:32
问题 What I'm trying to achieve is to run a series of observables conditionally. return observable.map(response => response) .flatmap(response1 => observable1(response1)) .flatmap(response2 => observable2(response2)) .flatmap(response3 => observable3(response3)) I need to check the response1 and invoke the remaining observables if needed, else I need to return response1 and break the execution and so on. I've gone through the following SO questions but they doesn't seem to answer my question

Angular service that returns observables/subjects from a cache array to multiple instances of a component in realtime

岁酱吖の 提交于 2019-12-06 05:05:48
USE CASE I have a content page that has multiple instances of UserActionsComponent. I also have a global DataService that acts as a data provider with (wannabe) advanced caching. Data fetch hierarchy: In-Memory Cache >> Browser Storage (async) >> HTTP Request UserActionsComponent Requests dataService.getData(URL,params,method) PS: params has details like blogId which makes the hash signature unique DataService (.getData()) 1) Makes a unique hash KEY using something like genUniqueHash(URL+stringify(params)+method) 2) Checks if value is present in an in-memory cache (array[KEY]) - If yes, return

Angular2 router with Http data service through a Resolve with Observable catching 404

倾然丶 夕夏残阳落幕 提交于 2019-12-06 05:04:34
In my resolve guard I am getting an Http Observable to return the JSON of a user from a particular id . I want to catch an error and reroute to the users overview if the id does not exist. I have seen code that solves that with a Promise, but not with an Observable. I would like to see a solution with an Observable! Currently I get an "EXCEPTION: Uncaught (in promise): Response with status: 404 Not Found for URL: http://127.0.0.1:3000/users/191" since user 191 does not exsist. Here is my code: Resolve: import { Injectable } from '@angular/core'; import { Resolve, ActivatedRouteSnapshot,

Reset timeout on event with RxJS

感情迁移 提交于 2019-12-06 04:35:57
I'm experimenting with RxJS (with the JQuery extension) and I'm trying to solve the following use case: Given that I have two buttons (A & B) I'd like to print a message if a certain "secret combination" is clicked within a given timeframe. For example the "secret combination" could be to click "ABBABA" within 5 seconds. If the combination is not entered within 5 seconds a timeout message should be displayed. This is what I currently have: var secretCombination = "ABBABA"; var buttonA = $("#button-a").clickAsObservable().map(function () { return "A"; }); var buttonB = $("#button-b")

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

我怕爱的太早我们不能终老 提交于 2019-12-06 04:25:54
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 letting it go through if it's only one single event during a non-busy time. Legacy API I also found that