Skip to content

Commit 66df3b8

Browse files
author
OpenShift Bot
authored
Merge pull request #1495 from spadgett/rootscope-event-cleanup
Merged by openshift-bot
2 parents 200c8cd + 262e1ae commit 66df3b8

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-18
lines changed

app/scripts/directives/deploymentMetrics.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ angular.module('openshiftConsole')
464464
}
465465
};
466466

467-
$rootScope.$on('metrics.charts.resize', function(){
467+
var unbindResizeHandler = $rootScope.$on('metrics.charts.resize', function(){
468468
MetricsCharts.redraw(chartByMetric);
469469
});
470470

@@ -474,6 +474,11 @@ angular.module('openshiftConsole')
474474
intervalPromise = null;
475475
}
476476

477+
if (unbindResizeHandler) {
478+
unbindResizeHandler();
479+
unbindResizeHandler = null;
480+
}
481+
477482
angular.forEach(chartByMetric, function(chart) {
478483
chart.destroy();
479484
});

app/scripts/directives/eventsSidebar.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ angular.module('openshiftConsole')
2424
$scope.collapsed = true;
2525
};
2626

27-
$rootScope.$on('event.resource.highlight', function(evt, data) {
27+
var messageHandlers = [];
28+
messageHandlers.push($rootScope.$on('event.resource.highlight', function(evt, data) {
2829
var targetKind = _.get(data, 'kind');
2930
var targetName = _.get(data, 'metadata.name');
3031
if (!targetKind || !targetName) {
@@ -35,9 +36,9 @@ angular.module('openshiftConsole')
3536
$scope.highlightedEvents[targetKind + "/" + targetName] = true;
3637
}
3738
});
38-
});
39+
}));
3940

40-
$rootScope.$on('event.resource.clear-highlight', function(event, data) {
41+
messageHandlers.push($rootScope.$on('event.resource.clear-highlight', function(event, data) {
4142
var targetKind = _.get(data, 'kind');
4243
var targetName = _.get(data, 'metadata.name');
4344
if (!targetKind || !targetName) {
@@ -48,10 +49,14 @@ angular.module('openshiftConsole')
4849
$scope.highlightedEvents[targetKind + "/" + targetName] = false;
4950
}
5051
});
51-
});
52+
}));
5253

5354
$scope.$on('$destroy', function() {
5455
DataService.unwatchAll(watches);
56+
_.each(messageHandlers, function(unbind) {
57+
unbind();
58+
});
59+
messageHandlers = null;
5560
});
5661
},
5762
};

app/scripts/directives/podMetrics.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ angular.module('openshiftConsole')
290290
var failureCount = 0;
291291

292292
function metricsSucceeded() {
293+
if (destroyed) {
294+
return;
295+
}
296+
293297
// Reset the number of failures on a successful request.
294298
failureCount = 0;
295299

@@ -519,7 +523,7 @@ angular.module('openshiftConsole')
519523
intervalPromise = $interval(update, MetricsCharts.getDefaultUpdateInterval(), false);
520524
});
521525

522-
$rootScope.$on('metrics.charts.resize', function() {
526+
var unbindResizeHandler = $rootScope.$on('metrics.charts.resize', function() {
523527
MetricsCharts.redraw(donutByMetric);
524528
MetricsCharts.redraw(sparklineByMetric);
525529
});
@@ -530,6 +534,11 @@ angular.module('openshiftConsole')
530534
intervalPromise = null;
531535
}
532536

537+
if (unbindResizeHandler) {
538+
unbindResizeHandler();
539+
unbindResizeHandler = null;
540+
}
541+
533542
angular.forEach(donutByMetric, function(chart) {
534543
chart.destroy();
535544
});

dist/scripts/scripts.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -10004,18 +10004,22 @@ type:"Warning"
1000410004
})), b.log("events (subscribe)", d.events);
1000510005
})), d.highlightedEvents = {}, d.collapseSidebar = function() {
1000610006
d.collapsed = !0;
10007-
}, c.$on("event.resource.highlight", function(a, b) {
10007+
};
10008+
var f = [];
10009+
f.push(c.$on("event.resource.highlight", function(a, b) {
1000810010
var c = _.get(b, "kind"), e = _.get(b, "metadata.name");
1000910011
c && e && _.each(d.events, function(a) {
1001010012
a.involvedObject.kind === c && a.involvedObject.name === e && (d.highlightedEvents[c + "/" + e] = !0);
1001110013
});
10012-
}), c.$on("event.resource.clear-highlight", function(a, b) {
10014+
})), f.push(c.$on("event.resource.clear-highlight", function(a, b) {
1001310015
var c = _.get(b, "kind"), e = _.get(b, "metadata.name");
1001410016
c && e && _.each(d.events, function(a) {
1001510017
a.involvedObject.kind === c && a.involvedObject.name === e && (d.highlightedEvents[c + "/" + e] = !1);
1001610018
});
10017-
}), d.$on("$destroy", function() {
10018-
a.unwatchAll(e);
10019+
})), d.$on("$destroy", function() {
10020+
a.unwatchAll(e), _.each(f, function(a) {
10021+
a();
10022+
}), f = null;
1001910023
});
1002010024
} ]
1002110025
};
@@ -11993,9 +11997,9 @@ containerName:a.containerMetric ? m.options.selectedContainer.name :"pod"
1199311997
}) :null;
1199411998
}
1199511999
function u() {
11996-
L = 0, _.each(m.metrics, function(a) {
12000+
H || (L = 0, _.each(m.metrics, function(a) {
1199712001
p(a), o(a);
11998-
});
12002+
}));
1199912003
}
1200012004
function v(a) {
1200112005
if (!H) {
@@ -12161,10 +12165,12 @@ delete a.data;
1216112165
});
1216212166
}), delete m.metricsError, A();
1216312167
}, !0), B = b(A, i.getDefaultUpdateInterval(), !1);
12164-
}), f.$on("metrics.charts.resize", function() {
12168+
});
12169+
var M = f.$on("metrics.charts.resize", function() {
1216512170
i.redraw(C), i.redraw(D);
12166-
}), m.$on("$destroy", function() {
12167-
B && (b.cancel(B), B = null), angular.forEach(C, function(a) {
12171+
});
12172+
m.$on("$destroy", function() {
12173+
B && (b.cancel(B), B = null), M && (M(), M = null), angular.forEach(C, function(a) {
1216812174
a.destroy();
1216912175
}), C = null, angular.forEach(D, function(a) {
1217012176
a.destroy();
@@ -12374,10 +12380,12 @@ b.$watch("options", function() {
1237412380
A = {}, y = null, delete b.metricsError, s();
1237512381
}, !0), t = a(s, h.getDefaultUpdateInterval(), !1), b.updateInView = function(a) {
1237612382
B = !a, a && (!z || Date.now() > z + h.getDefaultUpdateInterval()) && s();
12377-
}, e.$on("metrics.charts.resize", function() {
12383+
};
12384+
var G = e.$on("metrics.charts.resize", function() {
1237812385
h.redraw(u);
12379-
}), b.$on("$destroy", function() {
12380-
t && (a.cancel(t), t = null), angular.forEach(u, function(a) {
12386+
});
12387+
b.$on("$destroy", function() {
12388+
t && (a.cancel(t), t = null), G && (G(), G = null), angular.forEach(u, function(a) {
1238112389
a.destroy();
1238212390
}), u = null, x = !0;
1238312391
});

0 commit comments

Comments
 (0)