5 Star 4 Fork 1

HarmonyOS-TPC / RxBus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 3.95 KB
一键复制 编辑 原始数据 按行查看 历史
Abhijith 提交于 2021-05-19 17:27 . update README.md.

RxBus

RxBus : This is an event bus designed to allowing your application to communicate efficiently.RxBus support annotations(@produce/@subscribe), and it can provide you to produce/subscribe on other thread like MAIN_THREAD, NEW_THREAD, IO, COMPUTATION, TRAMPOLINE ,EXECUTOR, SINGLE and HANDLER. Also RxBus provide the event tag to define the event. The method's first (and only) parameter and tag defines the event type.

Usage Instructions

1 Just use the provided(Any Thread Enforce):

com.hwangjr.rxbus.RxBus

Or make RxBus instance is a better choice: :

public static final class RxBus {
    private static Bus sBus;

    public static synchronized Bus get() {
        if (sBus == null) {
            sBus = new Bus();
        }
        return sBus;
    }
}

2 Add the code where you want to register and unregister the class.

public class MainAbility extends Ability {
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        RxBus.get().register(/*  object whose methods should be registered */);
    }
    @Override
    protected void onStop() {
        RxBus.get().unregister(/*  object whose methods should be unregistered */);
        super.onStop();
    }
}

Inorder to post an event, obtain rxbus instance and use post method as shown below :

RxBus.get().post(/*Event tag to post*/, /*Event to post*/);

Installation Instructions

Library Dependencies

Rxbus is dependent on Rxohos, rxjava3 and reactive-streams.
  1. For using RxBus module in sample app,include the below library jar/har in libs folder of "rxbus" module to generate hap/rxbus.har:

    Rxbus module build.gradle should contain below dependency. dependencies { implementation 'io.reactivex.rxjava3:rxjava:3.0.4' implementation 'org.reactivestreams:reactive-streams:1.0.3' implementation 'io.openharmony.tpc.thirdlib:Rxohos:1.0.0' testCompile 'junit:junit:4.12' }

    Modify entry build.gradle as below :

    dependencies {
    	implementation project(':rxbus')
    	testCompile 'junit:junit:4.12'
    }
  2. For using Rxbus in separate application make sure to add the below dependent libraries in entry libs folder along with the main rxbus.har :

Rxbus module build.gradle should contain below dependency. dependencies { implementation 'io.reactivex.rxjava3:rxjava:3.0.4' implementation 'org.reactivestreams:reactive-streams:1.0.3' implementation 'io.openharmony.tpc.thirdlib:Rxohos:1.0.0' testCompile 'junit:junit:4.12' }

Modify entry build.gradle as below :
```
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
    testCompile 'junit:junit:4.12'
}
```
  1. For using Rxbus from a remote repository in separate application, add the below dependencies and include "rxohos.har" in libs folder of "entry" module :

Rxbus module build.gradle should contain below dependency. dependencies { implementation 'io.reactivex.rxjava3:rxjava:3.0.4' implementation 'org.reactivestreams:reactive-streams:1.0.3' implementation 'io.openharmony.tpc.thirdlib:Rxohos:1.0.0' testCompile 'junit:junit:4.12' }

Modify entry build.gradle as below :
```
	dependencies {
        implementation 'io.openharmony.tpc.thirdlib:RxBus:1.0.0'
        testCompile 'junit:junit:4.12'
	}

License

Copyright 2015 HwangJR, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
1
https://gitee.com/HarmonyOS-tpc/RxBus.git
git@gitee.com:HarmonyOS-tpc/RxBus.git
HarmonyOS-tpc
RxBus
RxBus
master

搜索帮助