Created
January 24, 2019 04:58
-
-
Save webhacking/6dbf509b2201ef91302bf1b0d5edf964 to your computer and use it in GitHub Desktop.
RxJS Example 05
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {from} from 'rxjs/internal/observable/from'; | |
import {distinctUntilChanged} from 'rxjs/operators'; | |
const source = [ | |
{x: 1, y: 1}, | |
{x: 1, y: 2}, | |
{x: 3, y: 5}, | |
{x: 6, y: 9}, | |
{x: 2, y: 1}, | |
{x: 3, y: 5}, | |
{x: 8, y: 5}, | |
{x: 2, y: 3}, | |
{x: 1, y: 2}, | |
{x: 9, y: 7}, | |
]; | |
const sequence$ = from(source); | |
const distance = 2.5; | |
sequence$ | |
.pipe( | |
distinctUntilChanged((prev, next) => { | |
return Math.sqrt((prev.x - next.x)**2 + (prev.y - next.y)**2) < distance | |
}) | |
) | |
.subscribe((val) => { | |
console.log(val) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment