Canh Ngo pushed to branch feature/cmng-psp1-CHANNELMGR-544 at cms-community / 
hippo-addon-channel-manager


Commits:
df828763 by Canh Ngo at 2016-04-06T15:13:56+02:00
CHANNELMGR-544: unsubscribed the 'delete-component' event when the controller 
is destroyed

Otherwise, when the controller object is created again, the  'delete-component' 
event is subscribed multiple times. It makes an event from ExtJs fires the 
method #deleteComponent() multiple times.

- - - - -


2 changed files:

- frontend-ng/src/angularjs/api/cms.service.js
- frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.controller.js


Changes:

=====================================
frontend-ng/src/angularjs/api/cms.service.js
=====================================
--- a/frontend-ng/src/angularjs/api/cms.service.js
+++ b/frontend-ng/src/angularjs/api/cms.service.js
@@ -56,9 +56,14 @@ export class CmsService {
     return iframeToHost.publish.apply(iframeToHost, args);
   }
 
-  subscribe(...args) {
+  subscribe(topic, callback, scope) {
     const hostToIFrame = this.getParentIFramePanel().hostToIFrame;
-    return hostToIFrame.subscribe.apply(hostToIFrame, args);
+    return hostToIFrame.subscribe(topic, callback, scope);
+  }
+
+  unsubscribe(topic, callback, scope) {
+    const hostToIFrame = this.getParentIFramePanel().hostToIFrame;
+    return hostToIFrame.unsubscribe(topic, callback, scope);
   }
 
   getConfig() {


=====================================
frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.controller.js
=====================================
--- a/frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.controller.js
+++ b/frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.controller.js
@@ -60,8 +60,11 @@ export class HippoIframeCtrl {
     ScalingService.init($element);
     DragDropService.init(this.iframeJQueryElement, 
$element.find('.channel-iframe-base'));
 
-    CmsService.subscribe('delete-component', (componentId) => {
-      this.deleteComponent(componentId);
+    const deleteComponentHandler = (componentId) => 
this.deleteComponent(componentId);
+    CmsService.subscribe('delete-component', deleteComponentHandler);
+    // unsubscribe the event when the controller is destroyed
+    $scope.$on('$destroy', () => {
+      CmsService.unsubscribe('delete-component', deleteComponentHandler);
     });
 
     $scope.$watch('iframe.editMode', () => this._updateDragDrop());



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/df828763eb440485b1f0e1d2a6eaa097a1f01035
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to