Get difference between last two values of an RxJS Observable

Efflam Daniel :

I have an observable tracking the scroll position

 const scroll = Observable
  .fromEvent(document, 'scroll')
  .map(e => window.pageYOffset)
  .startWith(0)

I would like to have a second observable tracking the scroll delta (newScroll - lastScroll)

const scrollDelta = scroll
  // ???
  .subscribe(delta => console.log('delta:', delta) )

How to implement something like this? I've tried with scan with no success. Thx

Brandon :

Use pairwise:

scroll
    .pairwise()
    .map([a, b] => b - a);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Get last message of Observable with RxJS

How get two or more values as an array from observable rxjs?

MYSQL Get Difference between two values

What is the difference between a Observable and a Subject in rxjs?

what is the difference between "new Observable()" and "of()" in RxJs

Difference between the methods .pipe() and .subscribe() on a RXJS observable

How to get the difference between two dates in Java including the last day?

Delay time between Observable values - RxJS

RxJS get before/after emission values of Observable

is there any difference between import { Observable } from 'rxjs/Observable' and import { Observable } from 'rxjs'?

How to get the absolute difference between values in two columns in a matrix

How to get the difference between two values on a time series in JavaScript?

How to get the compasison difference Column values between two tables in mysql

Is there a function to get the difference between two values on a pandas dataframe timeseries?

Get the average difference between two values in time period

Find difference between two values?

Rxjs: Difference between Observable.First vs Single vs Filter

Difference in importing Observable from 'rxjs/Observable' and 'rxjs'

Is there any difference between Observable and Future.get

Rxjs Observable array select between given start and end values

Comput the difference between two values for two dates?

Get difference between two lists

Get difference between two dates?

Get difference between two records

Get difference between two array

RxJs Observable duplicate values

How to get the difference between the first value and last value of two different column in Google BigQuery

How to get difference between two average values in PostgreSQL, where the averages are on a column, and the final table grouped by two columns?

Get difference between last and previous number