From 9615fd3e39350e16d79c41762b387059ecec784c Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Sat, 8 Aug 2020 14:30:53 -0400 Subject: [PATCH] update: common/components/ConfirmDocumentUnload --- .../components/ConfirmDocumentUnload.js | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/js/src/common/components/ConfirmDocumentUnload.js b/js/src/common/components/ConfirmDocumentUnload.js index d6e224ff9..774ed9806 100644 --- a/js/src/common/components/ConfirmDocumentUnload.js +++ b/js/src/common/components/ConfirmDocumentUnload.js @@ -17,21 +17,23 @@ import Component from '../Component'; * */ export default class ConfirmDocumentUnload extends Component { - config(isInitialized, context) { - if (isInitialized) return; - - const handler = () => this.props.when() || undefined; - - $(window).on('beforeunload', handler); - - context.onunload = () => { - $(window).off('beforeunload', handler); - }; + handler() { + return this.attrs.when() || undefined; } - view() { + oncreate(vnode) { + super.oncreate(vnode); + + $(window).on('beforeunload', this.handler); + } + + onremove(vnode) { + $(window).off('beforeunload', this.handler); + } + + view(vnode) { // To avoid having to render another wrapping
here, we assume that // this component is only wrapped around a single element / component. - return this.props.children[0]; + return vnode.children[0]; } }