标签:
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);
标签:
原文地址:http://www.cnblogs.com/Answer1215/p/5784167.html