Coder Social home page Coder Social logo

rxbus's Introduction

依懒库

//RxJava
compile 'io.reactivex:rxjava:1.1.6'
compile 'io.reactivex:rxandroid:1.2.1'
//RxLifecycle管理Rx的生命周期
compile 'com.trello:rxlifecycle:0.6.1'
compile 'com.trello:rxlifecycle-components:0.6.1'
//compile 'com.trello:rxlifecycle-kotlin:0.6.1'

调用

JitPack导包方式:

compile 'com.github.wittyneko:rxbus:0.1.0'

rxbus:0.1.0

发送消息

RxBus.getInstance().send("main", "来自Activity数据");

接收消息

RxBus.getInstance().with(this)
        .setCode(EventBusMsg.EMPTY) //过滤接收code
        .setUri("main") //过滤接收uri
        .observeOn(AndroidSchedulers.mainThread())
        .onNext(new Action1<EventBusMsg<String>>() {
            @Override
            public void call(EventBusMsg<String> msg) {
                 mBinding.mainTv.setText(msg.getContent());
                 Toast.makeText(getApplication(), "收到:" + msg.getUri() + ",消息:" + msg.getContent(), Toast.LENGTH_SHORT).show();
            }
       })

发送消息有多个实现,对应的接收通过setCodesetUri来进行过滤,默认code为0,uri为空字符串。

send

实现

实现很简单,无非就是建立可观察对象单例,接收的地方订阅消息接收。

info

具体的注释有说明,这里进行简单介绍。

  • AbsRxBus 是抽象的实现方式,发送和接收的方法在这里实现。
  • RxBusRxBusBehaviorRxBusReplsy是具体的单例实现,区别在于没有订阅者消息缓存方式。
  • EventBusMsg 消息对象,发送的消息最终会以一个EventBusMsg发送出去。
  • EventFilter 消息过滤机制,过滤接收消息,如果想加入更多判断可修改此处实现。
  • EventNext 消息接收,这里主要是为了防止catch后无法接收消息,没有什么特殊。
  • EventObservable RxBus的接口定义
  • EventSubscribeBuilder 构建订阅者,为了方便调用封装RxJava调用逻辑。

rxbus's People

Contributors

wittyneko avatar

Watchers

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