Code Monkey home page Code Monkey logo

rxstarter's Introduction

CircleCI ktlint

RxStarter

This is a starter project for demonstrating RxJava2

Get it on Google Play

Getting into RxJava

Work your way through these links to get into RxJava.

Link Reason to Read
Observer Pattern Background on Observer pattern and why a naive implementation can easily result in memory leaks. Luckily RxJava avoids this by design.
ReactiveX Intro RX's official intro to Reactive Programming. You've probably seen this and it feels lacking.
Functional Reactive An article which will explain the differences in mindset between reactive and imperative programming
Froussios Intro to RxJava A very definitive intro to RxJava basics. Must Read.
Froussios Intro to RxJava Seriously. This is the one. Read it.
Android Samples Samples of RxJava in Android. Ugly due to lack of Lambdas, but extensive examples.
RxJava repo This is the official repo but the documentation here is actually not that great for starting out. Don't feel bad if this doens't make a lot of sense.

Usage

The app has a number of samples that you can play around with in the app. There are shorthand explanations on each screen plus more detailed information in the code comments.

Each activity has a Java and Kotlin equivalent. The Kotlin classes are not just conversions of the Java classes. The Kotlin versions contain additional nice things such as Kotlin Extension functions.

The below tables lists the places in the code where each RxJava function is called. Observable Creation shows how you can go about creating an Observable that emits items.

Observable Creation Description Example
RxView.clicks() Creates an Observable out of clicks on any View Most of them. ButtonRapidClickActivity
.just() Create an Observable/Single from a function which returns a result. The function is fired once and the result retained. Easily used as substitute for Async. SingleActivity
.fromCallable() Create an Observable/Single from a function which returns a result. The function is fired only after subscribing, and again with initial subscriptions. Easily used as substitute for Async. LongApiCallActivity
.interval() Create an observable which emits an object every x milliseconds LongApiCallActivity, DistinctActivity
.merge() Merge two or more observables into one. Useful for running various events through the same filter. ThreadSwitchActivity
.mergeWith() Same as merge, just a different syntax. PinActivity
PublishSubject.create() Create an Observable you can send events to and subscribe to. ListActivity, ThreadSwitchActivity
publisher.hide() Turn a PublishSubject such as the one above into an observable that you can only listen/subscribe to. ListActivity

The Rx Operators Table list operators that can be applied to an rxJava chain.

Rx Operators Description Example
.subscribe() final action to take for each event. Can contain onNext(), onError() and/or onComplete() All of them
.map() Turn a given input into something else. Most of them. ButtonRapidClickActivity
.observeOn() Switches between threads, such as background and UI thread. Most of them, but especially ThreadSwitchActivity
.subscribeOn() Switches the initial Observable to a specified thread. LongApiCallActivity
.dispose() Clean up a subscription for Garbage Collection. Essential for preventing memory leaks. LongApiCallActivity, BaseActivity
.throttleFirst() Filters out any subsequent emissions past the first one in a given timeframe. ButtonRapidClickActivity
.scan() Keeps a single object which can be changed by each subsequent emission. Usually to keep a running tally. ButtonRapidClickActivity
.distinct() Filters out any emission which has occurred in the past. DistinctActivity
.distinct() Filters out any emission which has occurred in the past. DistinctActivity
.buffer() Keep emissions from reaching downstream until a given number or time has been reached. Useful for batching items. PinActivity
.donOnNext() Do something on each emission which doesn't affect the stream. Useful for side-effects or for doing something regardless of whether the end-result is filtered out or not. PinActivity
.doOnError() If there is any error, determines what should be done before reaching .subscribe() as an error FailingApiActivity

rxstarter's People

Contributors

jacquessmuts avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.