Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #19612 from atom/debounce-resize-event
Browse files Browse the repository at this point in the history
Debounce the resize event handler
  • Loading branch information
rafeca committed Jul 2, 2019
1 parent d6bcc17 commit 9fa3393
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions spec/window-event-handler-spec.js
@@ -1,5 +1,6 @@
const KeymapManager = require('atom-keymap');
const WindowEventHandler = require('../src/window-event-handler');
const { conditionPromise } = require('./async-spec-helpers');

describe('WindowEventHandler', () => {
let windowEventHandler;
Expand Down Expand Up @@ -50,10 +51,13 @@ describe('WindowEventHandler', () => {
});

describe('resize event', () =>
it('calls storeWindowDimensions', () => {
it('calls storeWindowDimensions', async () => {
jasmine.useRealClock();

spyOn(atom, 'storeWindowDimensions');
window.dispatchEvent(new CustomEvent('resize'));
expect(atom.storeWindowDimensions).toHaveBeenCalled();

await conditionPromise(() => atom.storeWindowDimensions.callCount > 0);
}));

describe('window:close event', () =>
Expand Down
7 changes: 6 additions & 1 deletion src/window-event-handler.js
@@ -1,5 +1,6 @@
const { Disposable, CompositeDisposable } = require('event-kit');
const listen = require('./delegated-listener');
const { debounce } = require('underscore-plus');

// Handles low-level events related to the `window`.
module.exports = class WindowEventHandler {
Expand Down Expand Up @@ -65,7 +66,11 @@ module.exports = class WindowEventHandler {
);
this.addEventListener(this.window, 'focus', this.handleWindowFocus);
this.addEventListener(this.window, 'blur', this.handleWindowBlur);
this.addEventListener(this.window, 'resize', this.handleWindowResize);
this.addEventListener(
this.window,
'resize',
debounce(this.handleWindowResize, 500)
);

this.addEventListener(this.document, 'keyup', this.handleDocumentKeyEvent);
this.addEventListener(
Expand Down

0 comments on commit 9fa3393

Please sign in to comment.