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

Commit

Permalink
Fix callback not removed (use workaround from KT-15101)
Browse files Browse the repository at this point in the history
  • Loading branch information
SerVB committed Aug 13, 2020
1 parent 199df9d commit 93def03
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ import org.w3c.dom.events.Event

class CloseBlocker(private val window: Window) {

private fun onBeforeUnload(e: Event) {
// Can't use simple function here because its reference isn't equal to itself: KT-15101
private val onBeforeUnload = fun(e: Event) {
require(e is BeforeUnloadEvent)

e.preventDefault()
e.returnValue = ""
}

fun setListener() {
window.addEventListener(beforeUnloadType, this::onBeforeUnload)
window.addEventListener(beforeUnloadType, onBeforeUnload)
}

fun removeListener() {
window.removeEventListener(beforeUnloadType, this::onBeforeUnload)
window.removeEventListener(beforeUnloadType, onBeforeUnload)
}

companion object {
Expand Down

0 comments on commit 93def03

Please sign in to comment.