# rxjs-exhaustmap-with-trailing

> A variant of RxJS exhaustMap that includes the trailing value emitted from the source observable while waiting for the inner observable to complete

Latest version **2.1.1** (published 2023-01-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install rxjs-exhaustmap-with-trailing
pnpm add rxjs-exhaustmap-with-trailing
yarn add rxjs-exhaustmap-with-trailing
bun add rxjs-exhaustmap-with-trailing
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2023-01-27 |
| First published | 2021-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 21.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Bjørge Næss |
| Maintainers | bjoerge |
| Keywords | rxjs, rx, observable, exhaust, exhaustMap, trailing, latest, switchMap, debounce |

## Links

- npm: https://www.npmjs.com/package/rxjs-exhaustmap-with-trailing
- Repository: https://github.com/bjoerge/rxjs-exhaustmap-with-trailing
- Homepage: https://github.com/bjoerge/rxjs-exhaustmap-with-trailing#readme
- Issues: https://github.com/bjoerge/rxjs-exhaustmap-with-trailing/issues
- npm.io page: https://npm.io/package/rxjs-exhaustmap-with-trailing

## Recent versions

- 2.1.1 (latest) — 2023-01-27
- 1.2.0 — 2022-09-20
- 2.1.0 — 2022-09-20
- 2.0.0 — 2021-05-01
- 1.1.0 — 2021-04-07
- 1.0.1 — 2021-03-26
- 1.0.0 — 2021-03-24

## README

# rxjs-exhaustmap-with-trailing

A variant of [RxJS exhaustMap](https://rxjs.dev/api/operators/exhaustMap) that includes trailing emissions from the source observable.

![Marble Diagram](./marbles.svg)

Just like the [`exhaustMap()`](https://rxjs.dev/api/operators/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()`](https://rxjs.dev/api/operators/exhaustMap) and [`debounce()`](https://rxjs.dev/api/operators/debounce).

## Usage

```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)
)
```

[Open CodeSandbox](https://codesandbox.io/s/recursing-haibt-rd1l6?file=/index.js)

## API

### exhaustMapWithTrailing

```
exhaustMapWithTrailing<T, R>(project: (value: T, index: number) => ObservableInput<R>): OperatorFunction<T, R>;
```

### exhaustMapToWithTrailing

```
exhaustMapToWithTrailing<T, R>(innerObservable: Observable<R>): OperatorFunction<T, R>;
```

## Credits

This is a packaged and unit tested version of the implementation posted by @aaronjensen here: https://github.com/ReactiveX/rxjs/issues/5004

---
_Source: https://npm.io/package/rxjs-exhaustmap-with-trailing · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
