Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split pane makes change detection run with every mousemove #53

Open
BlindDespair opened this issue Dec 5, 2018 · 0 comments
Open

Split pane makes change detection run with every mousemove #53

BlindDespair opened this issue Dec 5, 2018 · 0 comments

Comments

@BlindDespair
Copy link

I found a performance problem with the component. The MouseMove listener here is constantly listening for mousemove in ngZone which runs change detection for entire application all the time user moves mouse, although it's not even needed as it is supposed to only care about mousemove when isResizing is set. I can propose you couple solutions: inject NgZone into splitPane and change your method to something like

@HostListener('mousemove', ['$event'])
  onMousemove(event: MouseEvent) {
    this.ngZone.runOutsideOfAngular(() => {
       if (this.isResizing) {
         this.ngZone.run(() => {
            let coords = PositionService.offset(this.primaryComponent);
             this.applySizeChange(event.pageX - coords.left);
             return false;
         });
      }
    });
    }

This would quit angular zone for the handler and only reenter it when isResizing is set to true.
Other way to solve it is to use rxjs for event handling and only subscribe to mousemove event after mousedown and takeUntil mouseup. This way handler will be even non existent while not needed, but I assume it would require more refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant