Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/rxjs/2.3.22/rx.all.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
// `subscribe()`に渡すためのobserverを作成する。
var observer = Rx.Observer.create(function (num) {
    // 新しい値がプッシュされた時に
    return console.log("onNext: " + num);
}, function (error) {
    // エラーが起きた時に
    return console.log("onError: " + error);
}, function () {
    // 全ての値をプッシュし、ストリームが終了した時に
    return console.log('onCompleted');
});
 
Rx.Observable.from([1, 2, 3, 4, 5, 6, 7, 8])
    // 一要素ごとに500ミリ秒ずらす
    .delayWithSelector(function (num) {
        return Rx.Observable.timer(num * 500);
    }).filter(function (num) {
        return num % 2;
    }).map(function (num) {
        return num * num;
    }).subscribe(observer);
     
 
// => onNext: 1
// => onNext: 9
// => onNext: 25
// => onNext: 49
// => onCompleted
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x