# RxBus **Repository Path**: HarmonyOS-tpc/RxBus ## Basic Information - **Project Name**: RxBus - **Description**: event bus designed to allowing your application to communicate efficiently - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 1 - **Created**: 2021-04-01 - **Last Updated**: 2025-02-09 ## Categories & Tags **Categories**: harmonyos-toolkit **Tags**: None ## README # 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' } ``` 3. 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. ```