Giter Club home page Giter Club logo

invoking-message's Introduction

invoking-message

license version

invoking-message是一款Android平台消息总线框架,基于LiveEventBus实现。它颠覆了传统消息总线定义和使用的方式,通过链式的方法调用发送和接收消息,使用更简单。

logo

invoking-message的特点

  1. 基于LiveEventBus实现,具有LiveEventBus所有功能。
  2. 通过链式的方法调用发送和接收消息,使用起来更加简单。
  3. 只能使用预定义的消息,加强约束。
  4. 定义的消息更容易查找和溯源。
  5. 适合在组件化的架构中用来实现组件间的通信。

所以,无论你之前使用哪种消息总线框架,如果你曾经遇到如下问题,请尝试invoking-message,它能解决你的痛点:

  1. 随意定义消息,不易管理,一个消息想知道谁是发送者,谁又是观察者,只能通过Ctrl+F,非常麻烦,如果消息分布在不同组件中,查找起来就更加麻烦了。
  2. 消息定义越多,就越不清楚到底有哪些消息,写代码的时候是不是经常问自己:“哎,我该发送个什么消息来着?”。
  3. 编写代码的时候一不小心把消息写错了,又不会报错,怎么收不到消息了,查找问题好麻烦。

invoking-message的使用步骤

1. 定义消息

@InvokingEventsDefine()
public class DemoEvents {

    public static final String EVENT1 = "event1";

    @EventType(String.class)
    public static final String EVENT2 = "event2";

    @EventType(TestEventBean.class)
    public static final String EVENT3 = "event3";
}

关键点:

  1. 定义消息的类需加上注解@InvokingEventsDefine
  2. 消息的名字需要定义成public static final String类型
  3. 用注解@EventType定义消息体的类型,如不使用,默认为Object,@EventType支持自定义类型

2. 使用compiler

定义了消息的Module,需要在build.gradle中使用compiler处理注解:

annotationProcessor 'com.jeremyliao:invoking-message-compiler:1.0.1'

关键点:

  1. 注解处理器会生成以“EventsDefineAs”开头的接口文件
  2. 编写代码的时候,如果记不得定义了哪些消息,请查找以“EventsDefineAs”开头的类

3. 定义subscribers

InvokingMessage
        .get()
        .as(EventsDefineAsDemoEvents.class)
        .EVENT2()
        .observe(this, new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
                Toast.makeText(MainActivity.this, s, Toast.LENGTH_LONG).show();
            }
        });

关键点:

  1. 定义subscribers的整个过程为链式调用
  2. 支持更多定义subscribers的方式,与LiveEventBus一致

4. 发送消息

InvokingMessage
        .get()
        .as(EventsDefineAsDemoEvents.class)
        .EVENT2()
        .setValue("test");

关键点:

  1. 发送消息的整个过程为链式调用
  2. 支持更多发送消息的方式,与LiveEventBus一致

添加依赖

Via Gradle:

implementation 'com.jeremyliao:invoking-message-core:1.0.1'

混淆规则

-dontwarn com.jeremyliao.im.**
-keep class com.jeremyliao.im.** { *; }
-keep class com.jeremyliao.liveeventbus.** { *; }

示例

invoking-message适合在组件化的架构中用来实现组件间的通信,特别添加了一个在组件中使用invoking-message的Demo:demo

invoking-message's People

Contributors

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