BehaviorSubject vs PublishSubject

后端 未结 4 1353
北海茫月
北海茫月 2021-02-05 01:29

I\'m trying to get my head around the golden rule (if any) about:

When to use BehaviorSubject ?

and

When to

4条回答
  •  名媛妹妹
    2021-02-05 02:23

    The difference on BehaviourSubject and PublishSubject relies on how long they keep the data they captures, in instance the PublishSubject only keeps the data available at moment and keeps updating on every entry while BehaviourSubject keeps the last data inserted, so you may use for example to confirm password on a signup form and as an example for PublishSubject, performing a search and it has to update the data constantly in order to give accurate results and there's no too much necessity to compare data that are being inserted.

    As reference i leave this two photos from http://reactivex.io/documentation/subject.html

    PublishSubject

    BehaviourSubject

提交回复
热议问题