reactive-programming

RxJava - When and why to use Observable.share()

半城伤御伤魂 提交于 2019-12-03 07:03:48
I've seen patters like this: Observable<String> nameChanges = nameDataSource.changes().share(); // One subscriber autoUnsubscribe(nameChanges.subscribe(() -> { ... })); // Another subscriber autoUnsubscribe(nameChanges.map(...).filter(...).subscribe(...)); // autoUnsubscribe is called when the UI is torn down My question is: Why is it necessary to call share() whenever I want to listen to the Observable in multiple places? Why is not share() the default behavior for all observables? It would be nice if the code above worked the same even without .share() . I would not have to think about when

RXJS while loop for pagination

故事扮演 提交于 2019-12-03 07:00:50
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://swapi.co/api; let source = Observable.create(observer => { this.http.get(nextUrl, { headers: this

Reactive object bindings in a non-shiny context

妖精的绣舞 提交于 2019-12-03 06:55:55
问题 Actual question How could you either approximate the reactive environment/behavior established by shiny functions or possibly even use these very functions in a non-shiny context in order to create "reactive" variables? Background I'm absolutely fascinated by the shiny framework and its underlying paradigms. In particular with respect to the established overall reactive environment. Just for the pure fun of it, I wondered if one could transfer this reactive programming paradigm to a non-shiny

How to 'wait' for two observables in RxJS

和自甴很熟 提交于 2019-12-03 06:28:22
问题 In my app i have something like: this._personService.getName(id) .concat(this._documentService.getDocument()) .subscribe((response) => { console.log(response) this.showForm() }); //Output: // [getnameResult] // [getDocumentResult] // I want: // [getnameResult][getDocumentResult] Then i get two separated results, first of the _personService and then the _documentService . How can I wait for both results before call this.showForm() to finish an then manipulate the results of each one. 回答1:

How to use Observable.fromCallable() with a checked Exception?

戏子无情 提交于 2019-12-03 06:05:21
Observable.fromCallable() is great for converting a single function into an Observable. But how do you handle checked exceptions that might be thrown by the function? Most of the examples I've seen use lambdas and "just work". But how would you do this without lambdas? For example, see the quote below from this great article : Observable.fromCallable(() -> downloadFileFromNetwork()); It's a one-liner now! It deals with checked exceptions, no more weird Observable.just() and Observable.error() for such easy thing as deferring code execution! When I attempt to implement the above Observable

dynamic ggplot layers in shiny with nearPoints()

别说谁变了你拦得住时间么 提交于 2019-12-03 06:00:23
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() , eventReactive() and so on. Any help is much appreciated... library(shiny) library(ggplot2) shinyApp( ui =

Am I using reactive-banana right?

陌路散爱 提交于 2019-12-03 05:04:36
问题 Here's an example Haskell FRP program using the reactive-banana library. I'm only just starting to feel my way with Haskell, and especially haven't quite got my head around what FRP means. I'd really appreciate some critique of the code below {-# LANGUAGE DeriveDataTypeable #-} module Main where {- Example FRP/zeromq app. The idea is that messages come into a zeromq socket in the form "id state". The state is of each id is tracked until it's complete. -} import Control.Monad import Data

Event and Observable in FSharp

久未见 提交于 2019-12-03 04:53:57
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 ? The main difference between Event and Observable is in how they handle state and un-subscription. Event functions attach to the source event and do not give you any way

WebClient vs RestTemplate

穿精又带淫゛_ 提交于 2019-12-03 04:46:18
问题 As per spring 5: WebClient is an interface representing the main entry point for performing web requests. It has been created as a part of the Spring Web Reactive module and will be replacing the classic RestTemplate in these scenarios. The new client is a reactive, non-blocking solution that works over the HTTP/1.1 protocol Does that mean, we need to recode for the old applications using RestTemplate if we want to upgrade to Spring 5? Or there is some workaround to work with RestTemplate in

What is difference between observer pattern and reactive programming?

孤街浪徒 提交于 2019-12-03 04:04:40
问题 Recently I heard a lot the term reactive programming . But when I searched for it, what I discovered was only some similarities with observer pattern . Actually, I cannot find any different between them. What's conceptual difference between them and why the term reactive programming is getting buzzed? 回答1: Reactive programming is the general paradigm behind easily propagating changes in a data stream through the execution of a program. It's not a specific pattern or entity per-se, it's an