Skip to content

Commit

Permalink
Add reactive stream operators to demonstrate how event streams can be…
Browse files Browse the repository at this point in the history
… decorated.
  • Loading branch information
Josh Graber committed Nov 4, 2015
1 parent 3919002 commit f0c096c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions index.html
Expand Up @@ -12,6 +12,10 @@
<label>Hit count: </label>
<span>{{controller.hitCount}}</span>
</div>
<div>
<label>X pos: </label>
<span>{{controller.xPos}}</span>
</div>
<div>
<label>Error: </label>
<span>{{controller.error}}</span>
Expand Down
10 changes: 8 additions & 2 deletions js/controllers/eventConsumer/eventConsumer.controller.js
Expand Up @@ -17,8 +17,14 @@ function EventConsumerController($scope) {
oldSubscription.dispose();
}

oldSubscription = newValue.subscribe(function(data) {
$scope.$apply(function() { self.hitCount++; });
var xCoordStream = newValue.map(function(event) {
return {
position: event.offsetX,
};
}).sample(1000 /*ms*/);

oldSubscription = xCoordStream.subscribe(function(data) {
$scope.$apply(function() { self.hitCount++; self.xPos = data.position; });
}, function(error) {
$scope.$apply(function() { self.error = error; });
}, function() {
Expand Down

0 comments on commit f0c096c

Please sign in to comment.