Created
August 12, 2016 08:38
-
-
Save mrowa44/cf14a1966ee566141dd65d890077b6bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function WindowListener(windowEvents, windowHandler, capture = false) { | |
const events = (typeof windowEvents === 'string') ? [windowEvents] : windowEvents; | |
const handler = windowHandler || 'forceUpdate'; | |
return { | |
componentDidMount() { | |
for (let i = 0; i < events.length; i++) { | |
window.addEventListener(events[i], this[handler], capture); | |
} | |
}, | |
componentWillUnmount() { | |
for (let i = 0; i < events.length; i++) { | |
window.removeEventListener(events[i], this[handler], capture); | |
} | |
}, | |
}; | |
} | |
export default WindowListener; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment