Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

caught a couple of refactoring typos, and did some jshint cleanup

  • Loading branch information...
commit 272ec81522e471ad331bde600aa6b576d5da6da4 1 parent cd72dc7
Mark Mahoney authored March 23, 2012

Showing 1 changed file with 45 additions and 29 deletions. Show diff stats Hide diff stats

  1. 74  bndry/data-source.js
74  bndry/data-source.js
@@ -2,6 +2,8 @@ var bndry = bndry || {};
2 2
 if (!console) { var console = { log: function () {} }; }
3 3
 
4 4
 (function (bndry, $, undefined) {
  5
+  "use strict";
  6
+  
5 7
   var uid = 0,
6 8
       activeDataSources = [],
7 9
       transientFilterIDs = {};
@@ -61,7 +63,7 @@ if (!console) { var console = { log: function () {} }; }
61 63
           s, sLen,
62 64
           tmp;
63 65
 
64  
-      if (payload.constructor == Array) {
  66
+      if (payload.constructor === Array) {
65 67
         // nothing to do here
66 68
         return payload;
67 69
       }
@@ -86,7 +88,9 @@ if (!console) { var console = { log: function () {} }; }
86 88
 
87 89
         tmp = [];
88 90
         for (key in keys) {
89  
-          tmp.push(object[keys[key]]);
  91
+          if (keys.hasOwnProperty(key)) {
  92
+            tmp.push(object[keys[key]]);
  93
+          }
90 94
         }
91 95
 
92 96
         object.__key__ = tmp.join(":");
@@ -180,7 +184,7 @@ if (!console) { var console = { log: function () {} }; }
180 184
         var subscription,
181 185
             id;
182 186
 
183  
-        query = options.subscriber == 'opaque' ? "/opaque/" + org_id + "/" + query : "/query/" + org_id + "/" + query;
  187
+        query = options.subscriber === 'opaque' ? "/opaque/" + org_id + "/" + query : "/query/" + org_id + "/" + query;
184 188
         subscription = $.cometd.subscribe(query, handler);
185 189
 
186 190
         // NOTE: assuming cometd subscription object is an array that will return "query_name,integer" when toString is invoked
@@ -230,7 +234,7 @@ if (!console) { var console = { log: function () {} }; }
230 234
         // order first by port, then by protocol
231 235
         if (a.port < b.port) {
232 236
           order = -1;
233  
-        } else if (a.port == b.port) {
  237
+        } else if (a.port === b.port) {
234 238
           if (a.protocol < b.protocol) {
235 239
             order = -1;
236 240
           } else if (a.protocol > b.protocol) {
@@ -245,10 +249,10 @@ if (!console) { var console = { log: function () {} }; }
245 249
     };
246 250
 
247 251
     var process = {
248  
-      meters: function (o) { return o.sort(sorter['meters']); },
249  
-      country: function (o) { return o.sort(sorter['country']); },
  252
+      meters: function (o) { return o.sort(sorter.meters); },
  253
+      country: function (o) { return o.sort(sorter.country); },
250 254
       transport: function (o) {
251  
-        var values = o.sort(sorter['transport']),
  255
+        var values = o.sort(sorter.transport),
252 256
             ordered = [],
253 257
             i;
254 258
 
@@ -279,7 +283,9 @@ if (!console) { var console = { log: function () {} }; }
279 283
 
280 284
       // get all filter keys in sorted order
281 285
       for (key in obj) {
282  
-        keys.push(key);
  286
+        if (obj.hasOwnProperty(key)) {
  287
+          keys.push(key);
  288
+        }
283 289
       }
284 290
       keys.sort();
285 291
 
@@ -339,7 +345,7 @@ if (!console) { var console = { log: function () {} }; }
339 345
       } else {
340 346
         // streakerClient wasn't ready, so retry in a moment
341 347
         window.setTimeout(function () {
342  
-          requestAggregateQueryName(query, meters, callback);
  348
+          requestAggregatedQueryChannel(query, meters, callback);
343 349
         }, 100);
344 350
       }
345 351
     };
@@ -415,7 +421,9 @@ if (!console) { var console = { log: function () {} }; }
415 421
           msg.ext.flow_profile.name = '' + filterHash;
416 422
           msg.ext.flow_profile.filter = {};
417 423
           for (o in filter) {
418  
-            msg.ext.flow_profile.filter[o] = filter[o];
  424
+            if (filter.hasOwnProperty(o)) {
  425
+              msg.ext.flow_profile.filter[o] = filter[o];
  426
+            }
419 427
           }
420 428
 
421 429
           // store the query and callback for use when we get a response from cometd
@@ -492,8 +500,10 @@ if (!console) { var console = { log: function () {} }; }
492 500
             t;
493 501
 
494 502
         for (t in obj) {
495  
-          empty = false;
496  
-          break;
  503
+          if (obj.hasOwnProperty(t)) {
  504
+            empty = false;
  505
+            break;
  506
+          }
497 507
         }
498 508
 
499 509
         return empty;
@@ -506,7 +516,7 @@ if (!console) { var console = { log: function () {} }; }
506 516
 
507 517
           for (i = 0, len = removed ? removed.length : 0; i < len; ++i) {
508 518
             delete current[removed[i].__key__];
509  
-          };
  519
+          }
510 520
 
511 521
           for (i = 0, len = added ? added.length : 0; i < len; ++i) {
512 522
             current[added[i].__key__] = added[i];
@@ -541,7 +551,7 @@ if (!console) { var console = { log: function () {} }; }
541 551
         });
542 552
 
543 553
         return out;
544  
-      };
  554
+      }
545 555
 
546 556
       return function (msg) {
547 557
         var data = msg.data,
@@ -589,8 +599,6 @@ if (!console) { var console = { log: function () {} }; }
589 599
 
590 600
     // loop through subscribers and notify them of new data
591 601
     function update(data, force) {
592  
-      var s;
593  
-
594 602
       // only update subscribers if we aren't restarting
595 603
       if (!restarting || force) {
596 604
         data.state = state.update(data.added, data.removed);
@@ -599,17 +607,21 @@ if (!console) { var console = { log: function () {} }; }
599 607
         if (data.state || data.possiblyNoMeterData || force) {
600 608
 
601 609
           window.setTimeout(function () {
  610
+            var s;
  611
+
602 612
             for (s in subscribers) {
603  
-              try {
604  
-                updateSubscriber(subscribers[s], data);
605  
-              } catch (e) {
606  
-                // need to handle this generically so we still update the other subscribers
607  
-                if (e.stack) {
608  
-                  console.log(e.stack);
609  
-                } else if (e.stackTrace) {
610  
-                  console.log(e.stackTrace);
611  
-                } else {
612  
-                  console.log('Error: ' + e.type + ' - ' + e.message);
  613
+              if (subscribers.hasOwnProperty(s)) {
  614
+                try {
  615
+                  updateSubscriber(subscribers[s], data);
  616
+                } catch (e) {
  617
+                  // need to handle this generically so we still update the other subscribers
  618
+                  if (e.stack) {
  619
+                    console.log(e.stack);
  620
+                  } else if (e.stackTrace) {
  621
+                    console.log(e.stackTrace);
  622
+                  } else {
  623
+                    console.log('Error: ' + e.type + ' - ' + e.message);
  624
+                  }
613 625
                 }
614 626
               }
615 627
             }
@@ -646,7 +658,9 @@ if (!console) { var console = { log: function () {} }; }
646 658
             streakerID = WAITING;
647 659
 
648 660
             for (f in options.filter) {
649  
-              filter[f] = options.filter[f];
  661
+              if (options.filter.hasOwnProperty(f)) {
  662
+                filter[f] = options.filter[f];
  663
+              }
650 664
             }
651 665
 
652 666
             // grab meters from the aggregate value if it wasn't defined in filters
@@ -684,7 +698,9 @@ if (!console) { var console = { log: function () {} }; }
684 698
           // if this is a transient FP, we need to see if this disconnect will tear down the query set
685 699
           if (options.filter) {
686 700
             for (f in options.filter) {
687  
-              filter[f] = options.filter[f];
  701
+              if (options.filter.hasOwnProperty(f)) {
  702
+                filter[f] = options.filter[f];
  703
+              }
688 704
             }
689 705
 
690 706
             // grab meters from the aggregate value if it wasn't defined in filters
@@ -809,7 +825,7 @@ if (!console) { var console = { log: function () {} }; }
809 825
 
810 826
           // run an immediate update for this subscriber using the last update from streaker
811 827
           if ('state' in lastData) {
812  
-            udpateSubscriber(subscribers[id], lastData);
  828
+            updateSubscriber(subscribers[id], lastData);
813 829
           }
814 830
         }
815 831
       },

0 notes on commit 272ec81

Please sign in to comment.
Something went wrong with that request. Please try again.