-
Notifications
You must be signed in to change notification settings - Fork 384
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
Eliminate no-global-event-listener ESLint warnings #5732
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #5732 +/- ##
==========================================
Coverage 73.66% 73.66%
Complexity 5429 5429
==========================================
Files 186 186
Lines 16375 16375
==========================================
Hits 12063 12063
Misses 4312 4312
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Plugin builds for b406119 are ready 🛎️!
|
@@ -46,10 +46,12 @@ const addBeforeUnloadPrompt = () => { | |||
if ( beforeUnloadPromptAdded ) { | |||
return; | |||
} | |||
// eslint-disable-next-line @wordpress/no-global-event-listener | |||
window.addEventListener( 'beforeunload', onBeforeUnload ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to use global
here since the file is being transpiled via Webpack, which would then provide reference to window
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points. Might as well use global
in all these instances. Updated in 747061f
window.addEventListener( 'beforeunload', onBeforeUnload ); | ||
|
||
// Remove prompt when clicking trash or update. | ||
document.querySelector( '#major-publishing-actions' ).addEventListener( 'click', () => { | ||
// eslint-disable-next-line @wordpress/no-global-event-listener | ||
window.removeEventListener( 'beforeunload', onBeforeUnload ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same suggestion here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 747061f
@@ -144,6 +144,7 @@ class ErrorRows { | |||
} ); | |||
}; | |||
|
|||
// eslint-disable-next-line @wordpress/no-global-event-listener | |||
window.addEventListener( 'click', ( event ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same suggestion here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 747061f
Co-authored-by: Weston Ruter <westonruter@google.com>
Summary
Fixes #5731
This eliminates the
@wordpress/no-global-event-listener
ESLint warnings shown in #5731. A few different approaches were used:usedeslint-disable-next-line
to the three lines that had the issueglobal
is used instead ofwindow
.UnsavedChangesWarning
component, passed in the app root and used the root'sownerDocument
, because doing so was simple.useWindowWidth
hook, replacedwindow
withglobal
because that hook is intended to use the global window.Checklist