Giter VIP home page Giter VIP logo

rxjava2eventbus's Introduction

Rxjava2EventBus

Library for Event bus - implemented using RxJava2 in Android

Usage of the library :

  • Step 1 : Add following code in build.gradle in buildscript section
buildscript {
    repositories {
        jcenter()
    }
} 
  • Step 2 : Add the library in the dependencies section(build.gradle)
compile 'com.krinyny.reactive:rxjava2-eventbus:1.0.1'

As EventBus mechanism follows pub-sub pattern,there should be event publisher and subscriber for the event.

Following is the way to publish an event using this event bus.

EventBus.publishEvent(event);

"event" is of any class type(where data resides) so that subscriber can consume that event and perform action on top of it.

There are three modes of sending event.

Publish,Behaviour & Replay.

By Default, the event sent is of type "Publish". Different events can be sent in the following way

EventBus.publishEvent(event,EventBus.EventType.Behavior);

Following describes how to subscribe and consume an event:

EventBus.getFlowable(Event.class)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Event>() {
                    @Override
                    public void accept(@NonNull Event event) throws Exception {
                        //Do something with "event" object
                    }
                });

Different event processor can be defined as follows

EventBus.getFlowable(Event.class, EventBus.EventType.Behavior);
EventBus.getFlowable(Event.class, EventBus.EventType.Replay);

We can use different operators like map,flatmap,zip etc., while subscribing for an event.

We can also mention the thread on which it has to run & take action using subscribeOn & ObserveOn

In RxJava2 , to avoid back pressure Flowable is used.So using Flowable Processor we can send events.

Don't forget to dispose the Disposable after its usage

Disposable testDisposable = EventBus.getFlowable(Event.class).subscribe();

> use CompositeDisposible or dispose() method to dispose it.

To see it in action checkout the project and run the app.

Well, there is always room for improvements.Inbox me for suggestions @ [email protected]

rxjava2eventbus's People

Contributors

krishnachaitanya9984 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.