孤独プログラマー譚

孤独死が近い。

2020-08-14から1日間の記事一覧

RxJS 2度クリック防止

よくある「非同期通信が走るボタンクリックで、2度押し禁止」。 RxJSはexhaustMapで対応できる。 わざわざフラグ用の変数を作る必要がない。 const rx = require('rxjs'); const op = require('rxjs/operators'); rx.interval(100).pipe(op.take(5)) .pipe( …

RxJS exhaustMap, switchMap

exhaustMapは、後続の処理をキャンセル。 rx.of(1, 2, 3) .pipe( op.exhaustMap(obs), // 1 ) .subscribe(cl) switchMapは、先行の処理をキャンセル。 rx.of(1, 2, 3) .pipe( op.switchMap(obs), // 3 ) .subscribe(cl)