MVIKotlin学习笔记(1):简介


MVIKotlin

MVIKotlin是使用MVI模式的Kotlin多平台框架。

MVI

即Model-View-Intent。

ModelView之间的单向数据流。

img

核心组件

Store:MVI中的Model,写业务逻辑。

MviView:MVI中的View,写UI。

数据流动

  1. Store生产状态流(States)。

  2. States通过映射函数(Mapperfunction (f))转换为视图模型流(View Models)。

  3. View渲染View Models并生产视图事件流(View Events)。

  4. View Events通过另一个映射函数(anotherMapperfunction (f))转换为通信流(Intents)。

    img

Store也可以生产标签流(Labels)。

  1. Labels作为一次性事件转换为Intents用于重定向至另一个Stores
  2. Labels作为路由显示错误或其他与State无关的操作。

目的

使StoreView独立于其他过程。

Binder的作用

View通过Binder订阅View Models流。

Store通过Binder订阅Intents流。

Binder通过接收startstop信号管理订阅。