Giter Site home page Giter Site logo

kunminx / mvi-dispatcher Goto Github PK

View Code? Open in Web Editor NEW
288.0 3.0 37.0 680 KB

简明易用框架,解决 MVI 实战痛点

License: Apache License 2.0

Java 100.00%
android mvi androidx jetpack jetpack-android livedata livedata-viewmodel mutable mutablelivedata mvvm

mvi-dispatcher's Introduction

 

 

研发故事:《解决 MVI 架构实战痛点》

 

背景

响应式编程便于单元测试,但其自身存在漏洞,MVI 即是来消除漏洞,

MVI 有一定门槛,实现较繁琐,且存在性能等问题,难免同事撂挑子不干,一夜回到解放前,

综合来说,MVI 适合与 Jetpack Compose 搭配实现 “现代化的开发模式”,

反之如追求 “低成本、复用、稳定”,可通过遵循 “单一职责原则” 从源头把问题消除。

MVI-Dispatcher 应运而生。

 

 

收藏或置顶 顺滑转场 删除笔记

 

项目简介

笔者长期专注 “业务架构” 模式,致力消除敏捷开发过程中 “不可预期问题”。

在本案例中,我将为您展示,MVI-Dispatcher 是如何将原本 "繁杂易出错" 消息分发流程,通过 寥寥几行代码 轻而易举完成。

implementation 'com.kunminx.arch:mvi-dispatch:7.6.0'

//可选分支,简便安全完成 Config 读写
implementation 'com.kunminx.arch:keyvalue-dispatch:7.6.0'

 

一个完备的 “领域层” 消息分发组件,至少应满足以下几点:

1.内含消息队列,可暂存 “发送过且未消费” 的消息,

2.页面不可见时,队列暂存期间发来的消息,页面重新可见时,自动消费未消费的消息。

MVI-Dispatcher 应运而生,

 

此外,MVI-Dispatcher 改进和优化还包括:

1.可彻底消除 mutable 样板代码,一行不必写

2.可杜绝团队新手滥用 mutable.setValue( ) 于 Activity/Fragment

3.开发者只需关注 input、output 二处,从唯一入口 input 发起请求,并于唯一出口 output 观察

4.团队新手在不熟 LiveData、UnPeekLiveData、SharedFlow、mutable、MVI 情况下,仅根据 MVI-Dispatcher 简明易懂 input-output 设计亦可自动实现 “响应式” 开发

5.可无缝整合至 Jetpack MVVM 等模式项目

 

 

MVI-Dispatcher 以 “备忘录场景” 为例,提供完成一款 “记事本软件” 最少必要源码实现,

故通过该示例,您还可获得内容包括:

1.整洁代码风格 & 标准命名规范

2.对 “响应式编程” 知识点深入理解 & 正确使用

3.AndroidX 和 Material Design 全面使用

4.ConstraintLayout 约束布局使用

5.十六进制复合状态管理最佳实践

6.优秀用户体验 & 交互设计

 

Thanks to

感谢小伙伴浓咖啡、苏旗的测试反馈

AndroidX

Jetpack

SwipeDelMenuLayout

项目中图标素材来自 iconfinder 提供 免费授权图片

 

Copyright

本项目场景案例及 MVI-Dispatcher 框架,均属本人独立原创设计,本人对此享有最终解释权。

任何个人或组织,未经与作者本人当面沟通许可,不得将本项目代码设计及本人对 "响应式编程漏洞和 MVI" 独家理解用于 "打包贩卖、出书、卖课" 等商业用途。

如需引用借鉴 “本项目框架设计背景及思路” 写作发行,请注明链接出处

 

License

Copyright 2019-present KunMinX

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.

mvi-dispatcher's People

Contributors

kunminx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mvi-dispatcher's Issues

BaseFragment的addOnBackPressed()存在问题

##场景
新建一个fragment继承自BaseFragment,覆写onBackPressed,返回false,程序会死循环
##原因:
如果fragment中的onBackPressed返回false,那么事件会重新分发给该fragment,就死循环crash了
##目标:
当onBackPressed return false时,再次分发时过滤该OnBackPressedCallback

【 提问须知 】

如有 bug,请另外 new 一个 issue ⚠️⚠️⚠️

本项目开 issue 规范:

  1. 有任何 bug 都欢迎及时开 issue,我看到后则予以处理。
  2. 如有使用疑问,请先认真阅读 Readme 和源码 samples,在没有找到答案后,另外开 issue。
  3. 如开 issue 是为发表个人见解,请务必 客观、具体、严谨;严禁草率、乱入、带节奏:

务必注明观点所对应场景,并附上完整可复现代码,

不然很难构成有效交流。

任何缺乏实证依据和因果逻辑的泛泛而谈,都可能对其他使用者造成困扰。

在发表个人见解前,请先确保已认真阅读过源码。这是对自己、对作者、对其他读者最起码尊重。

livedate

项目中没有使用到databinding,请问页面状态state如何优雅的替换成 livedate。
旧项目比较庞大,替换datebinding 比较耗时,因此求教。

Lifecycle库版本报错提示

继承自MviDispatcher的类IDE会提示错误
Cannot access 'androidx.lifecycle.FullLifecycleObserver' which is a supertype of 'com.xx.zz.event.messenger.BlockMessenger'. Check your module classpath for missing or conflicting dependencies
看起来好像是Lifecycle版本冲突,但是不影响编译和运行。所有使用的地方都有红线提示,看起来有点难受。
现在项目用的Lifecycle版本是2.7.0,能否升级一下依赖库版本?

img_v3_027m_5c2f2e91-5cf1-4ffa-8aa5-4507878595eg
image

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.