I've been looking the documentations of RxJava1 https://github.com/ReactiveX/RxJava/releases and RxJava2 https://github.com/ReactiveX/RxJava/wiki/Reactive-Streams and seems like the unique different is that RxJava 2 has Java Stream.
Any other different?.
I've been working with Version 1.1.3 but I'm not sure if it's worth it move to RxJava2 since we're already using Java 8 streams in our code
Regards.
RxJava is a Java VM implementation of Reactive Extensions. where we can create asynchronous data stream on any thread, transform it and these asynchronous data streams can be consumed by Observers on any thread. What is RxKotlin? RxKotlin is a Kotlin implementation of Reactive Extensions.
RxJava can be used with any Java-compatible language, whereas Kotlin coroutines can only be written in Kotlin. This is not a concern for Trello Android, as we are all-in on Kotlin, but could be a concern for others. (Note that this just applies to writing code, not consuming it.
Single and Completable are new types introduced exclusively at RxJava that represent reduced types of Observable , that have more concise API. Single represent Observable that emit single value or error. You can think of the differences like the differences of a method that returns: Collection of Objects - Observable.
RxJava is a Java library that enables Functional Reactive Programming in Android development. It raises the level of abstraction around threading in order to simplify the implementation of complex concurrent behavior.
Both RxJava 1.x and 2.x are designed to be Java 6+ and thus we can't support Java 8 Streams in any of the versions. This was decided to keep support the myriad of Android devices and versions which won't ever get updated to a Java 8 compatible runtime. If you need Java 8 support, consider using Reactor-Core from Pivotal.
The major difference between the two is that 2.x targets the Reactive-Streams SPI directly and for this, it has been completely rewritten from scratch. We are currently in development preview mode which you can access as described in the 2.x branch readme.
The complete rewrite of 2.x improved our memory consumption and performance considerably; here is a benchmark that compares various versions and libraries.
On the API surface, we plan to keep supporting all operators that are present in 1.x and likely extend both versions with new ones for a few years before support on 1.x ends.
Since 2.x is a new architecture, many depending libraries (e.g., Retrofit) has to be updated as well; which likely won't happen earlier than end of this August or may as well take several months to catch up. Here is the wiki page that contains the highlights of the differences.
As I have implemented RxJava2 in my sample project - link
The following the differences between RxJava2 and RxJava1 :
To allow having RxJava 1.x and RxJava 2.x side-by-side, RxJava 2.x is under the maven coordinates io.reactivex.rxjava2:rxjava:2.x.y
and classes are accessible below io.reactivex
.
Users switching from 1.x to 2.x have to re-organize their imports, but carefully.
onCompleted
-> onComplete
- without the trailing d
CompositeSubscription
-> CompositeDisposable
- CompositeDisposable
as CompositeSubscription
and Subscription
have been removed
Func1
-> Function
Func2
-> BiFunction
limit
operator has been removed - Use take
in RxJava2
RxJava 2.0 has been completely rewritten from scratch on top of the Reactive-Streams specification. The specification itself has evolved out of RxJava 1.x and provides a common baseline for reactive systems and libraries.
Because Reactive-Streams has a different architecture, it mandates changes to some well known RxJava types.
RxJava2 has better performance and low memory usage over RxJava1
[Source: https://github.com/ReactiveX/RxJava/wiki/What%27s-different-in-2.0 ]
One of the major differences applies to the .filter
operator . As stated by the docs:
In addition, operators requiring a predicate no longer use
Func1<T, Boolean>
but have a separate, primitive-returning type ofPredicate<T>
(allows better inlining due to no autoboxing).
So for the .filter
operator , you will need to change like the example below
RxTextView.textChanges(editText)
.debounce(400, TimeUnit.MILLISECONDS)
.filter(new Predicate<CharSequence>() {
@Override
public boolean lengthOk(CharSequence charSequence) {
return charSequence.length() > 3;
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(/* attach your observer */);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With