LoginSignup
2
1

More than 5 years have passed since last update.

RxJSでズンドコ

Last updated at Posted at 2016-03-18

ズンドコキヨシについてはこちら ⇒ ズンドコキヨシまとめ

おもむろに RxJS & ES2015 でやってみました。

import {Rx} from 'rx';

const subject = new Rx.Subject();

function doZunDoko() {
    while (!subject.isStopped) {
        if (Math.random() > 0.5) {
            subject.onNext('ズン');
        } else {
            subject.onNext('ドコ');
        }
    }
}

const subscription = subject
    .doOnNext((aString) => console.log(aString))
    .bufferWithCount(5, 1)
    .filter((aArray) => aArray.join(',') === 'ズン,ズン,ズン,ズン,ドコ')
    .take(1)
    .subscribe(() => {
        console.log('キ・ヨ・シ!');
        subject.onCompleted();
        subscription.dispose();
    });

doZunDoko();

スクリーンショット 2016-03-18 23.40.25.png

実際の挙動はこちらから確認できます(GitHub Pages)。
http://hkusu.github.io/rxjs-zundoko/

コンソールを開いてください。

ソースは GitHub に置きました。
https://github.com/hkusu/rxjs-zundoko

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1