首页 > Web开发 > 详细

[RxJS] BehaviorSubject

时间:2016-08-18 15:57:49      阅读:222      评论:0      收藏:0      [点我收藏+]

When an Observer subscribe to a BehaviorSubject. It receivces the last emitted value and then all the subsequent values. BehaviorSubject requires that we provide a starting value, so taht all Observers will always receive a value when they subscribe to a BehaviorSubject.

 

Imagine we want to retreve a remote file and print its contents on an HTML page, but we wnat placeholder text while we wait for the contents. We can use a BehaviorSubject for this.

 

var subject = new Rx.BehaviorSubject(Waiting for content);
subject.subscribe(
function(result) {
  document.body.textContent = result.response || result;
},
function(err) {
  document.body.textContent = There was an error retrieving content;
}
);
Rx.DOM.get(/remote/content).subscribe(subject);

 

[RxJS] BehaviorSubject

原文:http://www.cnblogs.com/Answer1215/p/5784167.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!