// Ticker data will be updated every 3 seconds
// Show hand action will only trigger after user clicks a button
// When the user clicks the button, I want to use the last ticker price as the order price
let lastPrice: number;
this.ticker$
.do(ticker => lastPrice = ticker.closePrice)
.switchMap(() => this.showHand$)
.subscribe(showHand => {
this.order.price = lastPrice;
this.order.amount = showHand.amount;
this.order.type = showHand.type;
this.submit();
});
Any suggestions on how to preserve value and switch map together without using a one-line variable like above?