瀏覽代碼

HUE-6477 [frontend] Tighten null check on intervals and subscription utils

Enrico Berti 8 年之前
父節點
當前提交
fca053b

+ 2 - 2
desktop/core/src/desktop/static/desktop/js/hue.utils.js

@@ -471,7 +471,7 @@ var huePubSub = (function () {
       if (app) {
         Object.keys(topics).forEach(function (topicName) {
           topics[topicName].forEach(function (topic) {
-            if (typeof topic.app !== 'undefined' && (topic.app === app || topic.app.split('-')[0] === app)) {
+            if (typeof topic.app !== 'undefined' && topic.app !== null && (topic.app === app || topic.app.split('-')[0] === app)) {
               topic.status = 'paused';
             }
           });
@@ -482,7 +482,7 @@ var huePubSub = (function () {
       if (app) {
         Object.keys(topics).forEach(function (topicName) {
           topics[topicName].forEach(function (topic) {
-            if (typeof topic.app !== 'undefined' && (topic.app === app || topic.app.split('-')[0] === app)) {
+            if (typeof topic.app !== 'undefined' && topic.app !== null && (topic.app === app || topic.app.split('-')[0] === app)) {
               topic.status = 'running';
             }
           });

+ 3 - 3
desktop/core/src/desktop/static/desktop/js/hue4.utils.js

@@ -72,7 +72,7 @@
    */
   window.pauseAppIntervals = function (app) {
     hueIntervals.forEach(function (interval) {
-      if (typeof interval.app !== 'undefined' && (interval.app === app || (interval.app.split('-') && interval.app.split('-')[0] === app))) {
+      if (typeof interval.app !== 'undefined' && interval.app !== null && (interval.app === app || (interval.app.split('-') && interval.app.split('-')[0] === app))) {
         interval.status = 'paused';
         originalClearInterval(interval.id);
       }
@@ -84,7 +84,7 @@
    */
   window.resumeAppIntervals = function (app) {
     hueIntervals.forEach(function (interval) {
-      if (typeof interval.app !== 'undefined' && (interval.app == app || interval.app.split('-')[0] === app) && interval.status === 'paused') {
+      if (typeof interval.app !== 'undefined' && interval.app !== null && (interval.app == app || interval.app.split('-')[0] === app) && interval.status === 'paused') {
         interval.status = 'running';
         var id = originalSetInterval(interval.fn, interval.timeout);
         interval.id = id;
@@ -97,7 +97,7 @@
    */
   window.clearAppIntervals = function (app) {
     hueIntervals.forEach(function (interval) {
-      if (interval.app == app || (interval.app && interval.app.split('-')[0] === app)) {
+      if (interval.app == app || (typeof interval.app !== 'undefined' && interval.app !== null && interval.app.split('-')[0] === app)) {
         window.clearInterval(interval.originalId);
       }
     });

+ 2 - 2
desktop/core/src/desktop/static/desktop/spec/hue4UtilsSpec.js

@@ -40,7 +40,7 @@
     });
 
     it("should pause and resume all the intervals of an app", function (done) {
-      var id = window.setInterval(intervalCallback, 10, 'jasmine');
+      var id = window.setInterval(intervalCallback, 10, 'jasmine-dash');
       expect(intervalCallback).not.toHaveBeenCalled();
       window.pauseAppIntervals('jasmine');
       window.setTimeout(function () {
@@ -55,7 +55,7 @@
     });
 
     it("should clear the original interval id after a pause and resume", function (done) {
-      var id = window.setInterval(intervalCallback, 30, 'jasmine');
+      var id = window.setInterval(intervalCallback, 30, 'jasmine-dash');
       expect(intervalCallback).not.toHaveBeenCalled();
       window.pauseAppIntervals('jasmine');
       window.resumeAppIntervals('jasmine');