Electron window resize event



I’ve a problem with resizing event. I wish to attach my custom listener which would update my three.js canvas whenever the main window size will change. I was trying to use global window object and add my custom listener in traditional way:

document.addEventListener('resize', onWindowResize(), false);

But it dosen’t seem to work.


What if you attach your event listener to the window object instead of document?


The same, dosen’t matter it’s a window object or document the resolut from this is the same.

but anyway i’ve solved a problem just second a go using debounce method from loadash:

    let currentWindow = remote.getCurrentWindow().removeAllListeners();
    currentWindow.on('resize', _.debounce(function () {
    }, 100));

If you know better solution then this i’d appricicate.


Unless your onWindowResize function returns a function that is meant to handle the resize event that code doesn’t actually do what you think it does.


You’re totally right. My onWindowResize() function isn’t an actual handler for my event, it’s just a function statement. Adding first class function has solve the problem with running my function. Here is modified code:

    window.addEventListener('resize', function(e){

Thank you for your help guys!