A variant of RxJS exhaustMap that includes the trailing value emitted from the source observable while waiting for the inner observable to complete
npm install rxjs-exhaustmap-with-trailingA variant of RxJS exhaustMap that includes trailing emissions from the source observable.
Just like the exhaustMap() RxJS operator, exhaustMapWithTrailing() will ignore all emissions from source observable as long as the projected observable is pending, but in addition it will include the last emission received from the source observable before the projected observable completed. Think of it as a combination of exhaustMap() and debounce().
``js
import {exhaustMapWithTrailing} from "rxjs-exhaustmap-with-trailing"
import {delay} from "rxjs/operators"
import {fromEvent, of} from "rxjs"
const clicks = fromEvent(document, "click")
const result = clicks.pipe(
exhaustMapWithTrailing((value) => of(value).pipe(delay(1000)))
)
result.subscribe((event) =>
console.log("result: %d, %d", event.clientX, event.clientY)
)
`
``
exhaustMapWithTrailing
```
exhaustMapToWithTrailing
This is a packaged and unit tested version of the implementation posted by @aaronjensen here: https://github.com/ReactiveX/rxjs/issues/5004