Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rxjs-exhaustmap-with-trailing

bjoerge402.3kMIT2.1.1TypeScript support: included

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

rxjs, rx, observable, exhaust, exhaustMap, trailing, latest, switchMap, debounce

readme

rxjs-exhaustmap-with-trailing

A variant of RxJS exhaustMap that includes trailing emissions from the source observable.

Marble Diagram

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().

Usage

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

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

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.0.0 (2021-05-01)

⚠ BREAKING CHANGES

  • deps: Due to a change in the throttle() operator in RxJS 7, exhaustMapWithTrailing() now guarantees that the final value from the source observable gets emitted, even after the source has completed.

Features

  • deps: update rxjs peer dependency to 7.x and update test for trailing emmision (6a3006a)

1.1.0 (2021-04-07)

  • feat: defer to avoid sharing subject between subscribers (959ae75)

1.0.1 (2021-03-26)

  • chore: add marble diagram (aa329bd)
  • core: linkify readme, update example and add link to CodeSandbox (9820a6d)

1.0.0 (2021-03-24)