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

XMLWordPrintable

    • Type: New Feature
    • Resolution: Done
    • Priority: Normal
    • 9.6.0
    • Affects Version/s: 9.6.0
    • Component/s: None
    • Security Level: Jimmy
    • None

      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();
      });
      

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

              Created:
              Updated:
              Resolved: