首页 > 解决方案 > mouse drag issue with rxjs

问题描述

I am looking at the mouse drag example from learnrxjs.io, it looks pretty straight forward to me.

const mousedown$ = fromEvent(document, 'mousedown')
const mouseup$ = fromEvent(document, 'mouseup');
const mousemove$ = fromEvent(document, 'mousemove');

// after mousedown, take position until mouse up
mousedown$.pipe(
  mergeMap(_ => {
    return mousemove$.pipe(
      map((e: any) => ({
        x: e.clientX,
        y: e.clientY
      })),
      // complete inner observable on mouseup event
      takeUntil(mouseup$)
    )
  })
)
.subscribe(console.log);

However i can't figure out why the console is logging every second once I do the following:

Here is the stackblitz

Can someone help me clarify this? Thanks!

Edit: It seems to happen in Chrome version 79.0.3945.117 (Official Build) (64-bit). I cannot reproduce the issue in Firefox 72.0.1 (64-bit)...

Edit 2: finally ending up restarting my machine and the issue is gone...

标签: javascriptrxjs

解决方案


推荐阅读