BehaviorSubject vs PublishSubject

后端 未结 4 1388
北海茫月
北海茫月 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:25

    Publish Subject: Here, if a student entered late into the classroom, he just wants to listen from that point of time when he entered the classroom. So, Publish will be the best for this use-case.

    Behavior Subject: Here, if a student entered late into the classroom, he wants to listen the most recent things(not from the beginning) being taught by the professor so that he gets the idea of the context. So, here we will use Behavior.

提交回复
热议问题