D
D
Denis2017-11-25 15:27:51
PHP
Denis, 2017-11-25 15:27:51

What is the main concept of using RxJava?

While learning RXJava, I ran into difficulty understanding how it was intended to be used.
At the first acquaintance, I had an opinion that this is an implementation of the "Listener" pattern with useful features. That is, there is an object that generates events, and listeners subscribed to the object receive these events, while the object that generates events can exist from the beginning of the application to the very end.
But then I noticed that in all examples of using the library, there is always a ready-made data set that is passed to the Observable when it is created (except in cases where the Observable must generate events in repeating periods of time) and is never supplemented or replaced for an existing Observable.
From here I got the impression that Observable should be perceived as a one-time object.
That is, we have a data set, we create an Observable with this set and it exists until the set becomes obsolete, as soon as the set is obsolete, we unsubscribe all subscribers of our Observable and create a new Observable with a new data set, to which listeners subscribe again.
Some articles talk about how you can follow the data set on the keyboard using RXJava, of course they don’t give examples, but I found this example:
https://github.com/shekhargulati/rxjava-examples/b...
It uses an "eternal" loop to track keystrokes and it seems to me that this is not the best way to waste device resources.
Explain to me please, how is it supposed to use RXJava?
PS In my android project, I wanted to create an Observable in a service that does some work with the network and subscribe activities / fragments to it so that they react to changes from the outside. However, if the Observable has to be re-created for each request, then it becomes necessary to constantly re-subscribe listeners, which is not very convenient, although possible.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
irishmann, 2019-09-09
@twofolls95

Everything is fine with the session, the problem is in $_POST['submit'], you have not set any value for it, that is, in var_dump($_POST['submit']);is displayed as an empty string ( string '' (length=0)). You just check it if($_POST['submit']), in this case the expression is $_POST['submit']evaluated as a Boolean value, which means that both an empty string and null and 0 are considered as FALSE , more --> here <-- . In order for everything to work, you must either set value for button submitwith some value not equal to zero, or check it on the PHP side in another way, for example:

if(isset($_POST['submit'])){

}
//или просто 
if($_POST){

}

S
Sergey, 2017-11-25
@lacredin

RxJava is a library for implementing reactive style in java
a reactive style thing similar to the more well-known functional style of programming.
it is expressed in the following
there is a data stream, we apply some transformations to it and get a new stream.
for example
(the flow of requests to the network in the form of page addresses) -> Query OperatorNetwork -> Parsing Operator -> DataObjectFormation Operator -> (display on the screen)
Popularity in android, I think, gained due to the simplicity of working with multithreading. At least the first examples of application in android rx are usually about this.)
in general, this is a slightly different way of thinking. different from procedural and oop.
there is a source, there is a receiver and many transformations.
source is observable, destination is subscriber/observer . transformations are various kinds of operators or their chains.
In this case, we understand the application as threads of data flows. such a scheme is simpler than a scheme of objects. sometimes.
of course, we can also use hybrids of these paradigms.
all in all, it's worth a try. perhaps it is very close to you in the style of your thinking.

D
Denis Zagaevsky, 2017-11-25
@zagayevskiy

The concept of Rx is basically that there are data flows within the application. These streams start somewhere (create) and end somewhere (subscribe).
About data sets - I do not know, rather not. For example, there may be an infinite Observable that keeps track of the database. When you subscribe to it, it emits the current state of the database, when it changes, it emits more. You don't need a subscription for this.
What you are saying about an Observable that you subscribe to and work on regardless of that subscription is called a "hot" Observable. This can be done, but it's a little unclear why exactly the network needs this behavior. Why do we need an executing request if, perhaps, no one else subscribes to its result? In such a situation, a "cold" Observable is more useful, which starts the request on subscription and cancels it on unsubscribe.
Next, about keyboard input. See RxAndroid, and in particular RxTextView. In this case, it is absolutely the same - while no one is listening, you do not need to monitor the keyboard. When a subscriber appears, we start listening. And in the case of android, there is no way to install several listeners on one view, so do not be surprised when you call RxView.clicks(button).subscribe(Log::d) twice on one button, you will find that only the second Observable is emitting, and the first one is silent forever and ever.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question