Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-4943

Provide a before destroy callback / event when replacing an embedded instance for cleanup

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Normal Normal
    • 9.6.0
    • 9.6.0
    • None
    • Security Level: Jimmy

      User Story

      As an developper, I want to unsubscribe or update elements located on my outer page when i replace an embedded instance by a different one.

      This could be a callback or a listener to be triggered by the the zEmbedded.load method on the old desktop before cleaning up the page.

       

      Acceptance Criteria

      Developer can execute an action before the old desktop is unloaded. 

      Details

      POC:

      var originalDestroy = zEmbedded.destroy;
      zEmbedded.destroy = function (domId, skipError) {
      	if (typeof zk === 'undefined') {
      				if (skipError) return;
      				else throw new Error('zk is not loaded.');
      			}
      			var n = document.getElementById(domId);
      			if (n) {
      				var page = n.hasChildNodes() ? zk.$(n.firstChild) : null;
      				if (page) {
      					page.desktop.fire("onBeforeDestroy");
      				}
      			}
      
      	var result = originalDestroy.apply(this,arguments);
      	return result;
      }
      
      function loadZk(){
      	zEmbedded.load('zkapp', 'http://localhost:8080/zkembedded-app/index.zul?myparam=init-from-client-side')
      		.then(function(result) {
      			var myWin = result.widget;
      			myWin.desktop.listen({onBeforeDestroy:function(){
      				console.log("before destroy this desktop")
      			}});
      			
      		})
      		.catch(function(error) {
      			console.error(error);
      		});
      }
      clientSideButton.addEventListener('click', function() {
      	loadZk();
      });
      

            DevChu DevChu
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: