// ticker$ will update every 3s
// showHand$ will only triger after user click button
// I would like to take last ticker price as user order price when user click button
let lastPrice: number;
this.ticker$
// What I am doing now is preserve value to vairable here.
.do(ticker => lastPrice = ticker.closePrice)
.switchMap(() => this.showHand$)
.subscribe(showHand => {
// use value here
this.order.price = lastPrice;
this.order.amount = showHand.amount;
this.order.type = showHand.type;
this.submit();
});
上記のような1行の変数を使用せずに、値を事前に設定してマップを切り替える方法については、RxJS、値を保存して別のマップに切り替える方法
取るんどのような(1)でしょうか? –
take(n)は、showHand $からアイテムの数を制限し、n個のアイテムの後にcomplete()を送出します。これを完全にすると自動的にサブスクリプションが停止されます。 –