ReSwift源码学习笔记

192 阅读1分钟

Subscription 类的作用

总的来说这个类的最主要作用是操作State 和 回调外部(observer) Subscription类有下面几个方法 select方法,init方法,observer方法,newValues方法

select方法

select方法 可以生成一个新的Subscription 对象,并且State 转换成subState

init(sink:) 方法

select 方法调用 init(sink:)方法 ,生成一个新的Subscription 也就是 transformedSubscription

observer方法

通过observe 方法 回调最新的State 到外部

看了很久,终于知道ReSwift 如果在subscribe 订阅方法中,通过select 函数,把具体需要的State 返回给 外部了( func newState(state: MenuState) {} )

ReSwift的工作流程图

RxSwift的Observable工作流程.png