码迷,mamicode.com
首页 > Web开发 > 详细

[RxJS] BehaviorSubject

时间:2016-08-18 15:57:51      阅读:470      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!