reactive-programming

RXJS while loop for pagination

我们两清 提交于 2019-12-03 17:50:37
问题 I try to query all people data from the swap api. The URL swapi.co/api/people returns an object with an people array and the URL(swapi.co/api/people/?page=2) where I get the next data from. What I want to do is that the subscribe method updates the angular component every time a new page is available. I’m new to the reactive programming model. How can I implement a while loop or a sequence of Observables? This works for the first page: getAllPeople(): Observable<Person[]> { let nextUrl = http

dynamic ggplot layers in shiny with nearPoints()

大兔子大兔子 提交于 2019-12-03 17:03:17
问题 I'm familiar with the basics of shiny but struggling with something here. I would like to be able to add a ggplot layer when a point is clicked to highlight that point. I know this is possible with ggvis and there is a nice example in the gallery, but I would like to be able to use nearPoints() to capture the click as ui input. I have tried something (see below) which works apart from the ggplot layer appears and then disappears. I have tried all kinds of edits to this with reactive() ,

Event and Observable in FSharp

廉价感情. 提交于 2019-12-03 16:26:58
问题 Is it equivalent/better to work with the Event module on Event type or with Observable on the publish property of an event Functionally it seems equivalent, and I guess the difference is 'semantic' : Are we inside the boundary where it makes sense to have access to the internal state of the event ? Or are we considering this event interface as a passive source from which a stream was exposed to us Is that the correct thinking ? 回答1: The main difference between Event and Observable is in how

RxJava retryWhen bizarre behavior

萝らか妹 提交于 2019-12-03 15:39:21
I'm playing with the RxJava retryWhen operator. Very little is found about it on the internet, the only one worthy of any mention being this . That too falls short of exploring the various use cases that I'd like to understand. I also threw in asynchronous execution and retry with back-off to make it more realistic. My setup is simple: I've a class ChuckNorrisJokesRepository that returns random number of Chuck Norris jokes from a JSON file. My class under test is ChuckNorrisJokesService which is shown below. The use cases I'm interested in are as follows: Succeeds on 1st attempt (no retries)

RxJava: how to compose multiple Observables with dependencies and collect all results at the end?

北战南征 提交于 2019-12-03 15:03:55
问题 I'm learning RxJava and, as my first experiment, trying to rewrite the code in the first run() method in this code (cited on Netflix's blog as a problem RxJava can help solve) to improve its asynchronicity using RxJava, i.e. so it doesn't wait for the result of the first Future ( f1.get() ) before proceeding on to the rest of the code. f3 depends on f1 . I see how to handle this, flatMap seems to do the trick: Observable<String> f3Observable = Observable.from(executor.submit(new

Testing in reactive-banana

試著忘記壹切 提交于 2019-12-03 14:50:00
Is there a way to unit test networks created in reactive banana? Say I've built up some network with some input events - is it possible to verify that events have produced some output stream/behaviours have some value after some number of input events. Does it even make sense to do this? I noticed there are various interpret* functions but couldn't seem to work out how to use them. There's also the Model module which looks ideal for testing but has completely different types to the real implementation. When you say "unit test," I'm imagining something like QuickCheck , where you inject a

Is RxJS faster than imperative? [closed]

喜欢而已 提交于 2019-12-03 14:07:57
I'm newer in functional programming and functional reactive programming. I read a lot of times the great power of functional reactive programming . Okey; is readable, avoid side effects, etc. But... I don't know how to improve my code in functional/reactive way to execute faster than imperative way. Is it possible? Maybe I miss something? Because in my functional programming code is iterating for every task: for filter, map, reduce... And this is slower. Is possible to do all things iterating once? Maybe using compose() ? Thanks. Performance test: Imperative vs FP vs FRP var array = []; var i,

how to avoid glitches in Rx

二次信任 提交于 2019-12-03 13:12:05
问题 Unlike other "FRP" libraries, Rx doesn't prevent glitches: callbacks invoked with time-mismatched data. Is there a good way to work around this? As an example, imagine that we have a series of expensive computations derived from a single stream (e.g. instead of _.identity, below, we do a sort, or an ajax fetch). We do distinctUntilChanged to avoid recomputing the expensive things. sub = new Rx.Subject(); a = sub.distinctUntilChanged().share(); b = a.select(_.identity).distinctUntilChanged()

Can I save the old value of a reactive object when it changes?

点点圈 提交于 2019-12-03 12:26:12
Note: After coming up with the answer I reworded the question to make if clearer. Sometimes in a shiny app. I want to make use of a value selected by the user for a widget, as well as the previous value selected for that same widget. This could apply to reactive values derived from user input, where I want the old and the new value. The problem is that if I try to save the value of a widget, then the variable containing that value has to be reactive or it will not update every time the widget changes. But, if I save the the value in a reactive context it will always give me the current value,

Why should we use Behavior in FRP

徘徊边缘 提交于 2019-12-03 11:53:32
I am learning reactive-banana. In order to understand the library I have decide to implement a dummy application that would increase a counter whenever someone pushes a button. The UI library I am using is Gtk but that is not relevant for the explanation. Here is the very simple implementation that I have come up with: import Graphics.UI.Gtk import Reactive.Banana import Reactive.Banana.Frameworks makeNetworkDescription addEvent = do eClick <- fromAddHandler addEvent reactimate $ (putStrLn . show) <$> (accumE 0 ((+1) <$ eClick)) main :: IO () main = do (addHandler, fireEvent) <- newAddHandler