V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
jeremyliao
V2EX  ›  Android

第一个上 k 的 GitHub 项目「LiveEventBus」

  •  
  •   jeremyliao · 2019-07-09 11:43:58 +08:00 · 4975 次点击
    这是一个创建于 1725 天前的主题,其中的信息可能已经有所发展或是发生改变。
    「 LiveEventBus 」 https://github.com/JeremyLiao/LiveEventBus

    非常好用的消息总线框架
    4 条回复    2019-07-31 11:22:05 +08:00
    songdehuai
        1
    songdehuai  
       2019-07-10 09:51:33 +08:00
    已 star,学习一下
    jeremyliao
        2
    jeremyliao  
    OP
       2019-07-10 15:09:30 +08:00
    snoppy
        3
    snoppy  
       2019-07-11 15:20:28 +08:00
    学习, 已 star
    loopq
        4
    loopq  
       2019-07-31 11:22:05 +08:00
    来挖坟,学习一下还可以,毕竟使用了最新的技术。不过实际项目中可能不会使用,说一下我的看法,希望不会冒犯
    1.发送事件和接收事件都需要相同的一个 Key,这样项目中会需要一个文件来维护这个 Key
    2.接收事件的是这么用的。
    LiveEventBus.get()
    .with(KEY_TEST_CLOSE_ALL_PAGE, Boolean.class)
    .observe(this, new Observer<Boolean>() {
    @Override
    public void onChanged(@Nullable Boolean b) {
    if (b) {
    finish();
    }
    }
    });
    我们项目中一个 event processor 可能会有 20 个 event,用你的这个写法第一个不够清晰,第二个代码感觉太冗余了。

    顺便:我们项目中用的是 greenboot 家的 eventbus
    整个发送流程是这样的
    /**
    * event 实体
    */
    public class ShowLandingEvent{
    ...
    }

    // 发送事件
    BusProvider.post(new ShowLandingEvent(...) )

    // 接收事件
    public void ShowLandingEvent(ShowLandingEvent event){
    ....
    }

    个人感觉,会比你的清晰很多。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2691 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:29 · PVG 23:29 · LAX 08:29 · JFK 11:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.