Reactive Programming with RxJava-Chapter2:Reactive Extensions

Anatomy of rx.Observable

Indeed,Observablecan actually produce three types of events:

  • Values of type T,as declared by Observable
  • Completion event
  • Error event

Subscribing to Notifications from Observable

Controlling Listener by Using Subscription and Subscriber

Creating Observables

1、Mastering Observable.create()

Managing Multiple subsscribers

  • cache()

2、Infinite Streams

Two techniques for subscriber to clean up resource when unsubscribes
- if(subscriber.isUnsubscribed()){…}
- subscriber.add(Subscriptions.create(…))

You should not use explicit threads inside create()
It is a good practise to wrap entire expressions within create() in a try-catch block.Throwables should be propagated downstream rather than logged or rethrown.

Timing:timer() and interval()

  • timer()timer()
  • interval()interval()

Hot and Cold Observables

Observablecoldhot
deliver of eventsreceive a complete and consistent set of eventsdon`t know whether received all events from the beginning
time dependencythe exact instant when an item was created is irrelevantrepresent events as they come,typically from some external source

How to multiplex a single upstream source to multiple Observers

1、rx.subjects.Subject

Subjects are useful,but there are many subtleties you must understand.For example,after calling subject.onError(),the Subject silently drops subsequent onError notifications,effectively swallowing them

  • PublishSubject
  • AsyncSubject
  • BehaviorSubject
  • ReplaySubject

2、ConnectableObservable

Single Subscription (Observable.share())

No matter how many Subscribes connect to ConnectableObservable,it opens just one subscription to the Observable from which it was created
- Observable.publish()
- ConnectableObservable.refcount();

ConnectableObservable Lifecycle

Force subscription in absence of any Subscriber
- Observable.publish()
- ConnectableObservable.connect();

autoConnect() (since 1.2)

  • Observable.publish()
  • ConnectableObservable.autoConnect();

最后,安利一款自己写的基于MVP的Android开发框架

https://github.com/sxenon/Pure
欢迎大家拍砖,如果觉得好,麻烦多多star

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值