-
Notifications
You must be signed in to change notification settings - Fork 0
Exploring RxKotlin

-
Origins of RxKotlin: RxKotlin is derived from Rx, where Rx stands for Reactive Extensions. It is based on a set of standard principles applicable to various programming platforms. Reactive programming principles provide a standardized approach, making it easier to write and maintain code across different platforms.
-
Rx Principles: Rx is centered around reactive programming principles, offering a standard methodology across multiple programming environments. This consistency aids in organizing code concisely, enhancing readability, and simplifying maintenance.
-
RxKotlin and RxJava: RxKotlin serves as the Kotlin bindings for RxJava. Kotlin, being interoperable with Java, allows direct utilization of RxJava within Kotlin code. RxKotlin acts as a layer on top of RxJava, providing lightweight extension functions that facilitate seamless communication with Kotlin.
-
RxAndroid: RxAndroid, on the other hand, serves as the RxJava bindings specifically tailored for Android development. It enables the application of reactive programming principles in Android applications.
-
Interoperability: Due to the interoperability between Java and Kotlin, developers can seamlessly integrate RxJava into Kotlin code, making use of RxKotlin for additional Kotlin-specific functionalities.
-
Asynchronous Programming: RxKotlin is an asynchronous programming library centered around the concept of observables. Observables represent sequences of data, which could include continuous button clicks, data from a server, or any other stream of events over time.
-
Observables: Observables, in the context of RxKotlin, are sequences of data or events. These could be responses to user interactions, server communications, or any other time-dependent data.
- Everything is a Sequence: The fundamental principle of RxKotlin is that everything is a sequence or something that reacts to a sequence. This underscores the central role of sequences in the reactive programming paradigm.
- Button Taps
- Keyboard Animations
- Downloading data
- Processing events
- Writing to disc
- Playing the audio and video
- Threads
- Runnables
- AsyncTask
- Coroutines
- WorkManager
- We have so many APIs in Android to deal with asynchronicity
- RxKotlin makes it a simpler solution to manage async things instead of relying on multiple APIs
- RxKotlin is reactive.
- It contains a wide variety of patterns and operators.
- The operators used to comply with other Rx standards used in other platforms.
- RxKotlin helps to manage any possible side effects by properly managing the mutable state.
- It helps to write code in a compositional way so that it is easier to reasonably explain the code by revisiting it compared to the traditional approach.
- RxKotlin supports code isolation
- RxKotlin supports decoupling
- RxKotlin enables reusability
- Rx concept is the multiplatform meaning we can apply skills for another platform similarly and helps to reason with other developers of other platform
- It has a steep learning curve to learn all the aspects of the programming using the reactive.
- People who follow the regular traditional approach of programming need to practice & understand the reactive way of coding.
- If you have a tight deadline, It is not the proper time to incorporate learning rxKotlin to your project.
- We need a couple of dependencies to be added to the project to work with it like
rxjava,rxandroid, andrxextension. It might be small but still, it's quite a couple of dependencies that we use. - We need not have to use
rxkotlinwhen all other developers in the project are not interested in learningrxkotlinalso because they have to understand your code right. - If you use it without understanding, you can get into complications.
- Observable & Observer also sometimes known as Publisher & Subscriber
- We create a sequence of observables and reactively observe them.
- An observable won't emit them until there are one or more subscribers.
-
Successful Cycle
- Here is a sequence of events is triggered one after another
- On each emission
onNextevent is triggered - If there is not interruption dure to error,
Completedevent is triggered
-
Un-Successful Cycle
- Here is a sequence of events are triggered one after another
- On each emission
onNextevent is triggered - If there is a interruption, now
OnErrorevent is triggered, theOnNextevent is not triggered after the error is found, FinallyOnCompletionis not triggered.
