Skip to content

Instantly share code, notes, and snippets.

@jesperlandberg
Created July 30, 2019 06:33
Show Gist options
  • Select an option

  • Save jesperlandberg/824637624d8e14c6f8e51173d6fa1e70 to your computer and use it in GitHub Desktop.

Select an option

Save jesperlandberg/824637624d8e14c6f8e51173d6fa1e70 to your computer and use it in GitHub Desktop.
startLoop = () => {
this.loop = setInterval(this.someMethod, 5000)
}
clearLoop = () => {
clearInterval(this.loop)
}
onFocus = () => {
this.startLoop()
}
onBlur = () => {
this.clearLoop()
}
addListeners = () => {
window.addEventListener('focus', this.onFocus)
window.addEventListener('blur', this.onBlur)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment