Yangman - changed loop types 28/44128/2
authorLubomir Balogh <lubalogh@cisco.com>
Wed, 17 Aug 2016 09:28:56 +0000 (11:28 +0200)
committerDaniel Malachovsky <dmalacho@cisco.com>
Thu, 18 Aug 2016 14:57:30 +0000 (16:57 +0200)
Bug 6394 - Review for YangMan

- Using Object.keys().forEach instead of for in loop
- Using native map, some, filter functions

Change-Id: I1a80782badaa93d6201797fa4c7cb2850b8d7b1c
Signed-off-by: Lubomir Balogh <lubalogh@cisco.com>
modules/common-yangutils-resources/src/main/resources/yangutils/services/node-wrapper.services.js
modules/yangman-resources/src/main/resources/yangman/models/collectionlist.model.js

index e28ab4038ce252b4ad95343e1961793ad5f914b2..af091f2ce733dfb7262685131095abea3a0b4eca 100644 (file)
@@ -170,9 +170,9 @@ define([], function () {
                 }
 
                 node.actElemStructure.clear();
-                for (var prop in actData) {
+                Object.keys(actData).forEach(function(prop) {
                     node.actElemStructure.fillListElement(prop, actData[prop]);
-                }
+                });
 
                 EventDispatcherService.dispatch(constants.EV_LIST_CHANGED, node.actElemStructure);
             };
@@ -196,9 +196,9 @@ define([], function () {
                     var actData = node.listData[node.actElemIndex];
 
                     node.actElemStructure.clear();
-                    for (var prop in actData) {
+                    Object.keys(actData).forEach(function(prop) {
                         node.actElemStructure.fillListElement(prop, actData[prop]);
-                    }
+                    });
                 }
 
                 EventDispatcherService.dispatch(constants.EV_LIST_CHANGED, node.actElemStructure);
@@ -225,11 +225,11 @@ define([], function () {
 
                 var buildedDataCopy = node.listData.slice().map(function (item) {
                     var newItem = {};
-                    for (var prop in item){
+                    Object.keys(item).forEach(function(prop) {
                         if (prop !== '$$hashKey'){
                             newItem[prop] = item[prop];
                         }
-                    }
+                    });
                     return newItem;
                 }).filter(function (item){
                     return Object.keys(item).length !== 0;
@@ -257,9 +257,10 @@ define([], function () {
                     node.createStructure();
                     node.listData = array.slice();
                     node.actElemIndex = node.listData.length - 1;
-                    for (var prop in node.listData[node.actElemIndex]) {
+
+                    Object.keys(node.listData[node.actElemIndex]).forEach(function(prop) {
                         node.actElemStructure.fillListElement(prop, node.listData[node.actElemIndex][prop]);
-                    }
+                    });
                 }
 
                 return (match && array.length > 0);
@@ -544,9 +545,9 @@ define([], function () {
 
                 if (match && nodesToFill.length) {
                     nodesToFill.forEach(function (child) {
-                        for (var prop in data) {
+                        Object.keys(data).forEach(function(prop) {
                             child.fill(prop, data[prop]);
-                        }
+                        });
                     });
                     node.expanded = match;
                 }
@@ -605,9 +606,9 @@ define([], function () {
 
                 if (match && nodesToFill.length) {
                     nodesToFill.forEach(function (child) {
-                        for (var prop in data) {
+                        Object.keys(data).forEach(function(prop) {
                             child.fill(prop, data[prop]);
-                        }
+                        });
                     });
                     node.expanded = match;
                 }
@@ -668,9 +669,9 @@ define([], function () {
 
                 if (match && nodesToFill.length) {
                     nodesToFill.forEach(function (child) {
-                        for (var prop in data) {
+                        Object.keys(data).forEach(function(prop) {
                             child.fill(prop, data[prop]);
-                        }
+                        });
                     });
                 }
 
@@ -749,9 +750,9 @@ define([], function () {
 
                 if (match && nodesToFill.length) {
                     nodesToFill.forEach(function (child) {
-                        for (var prop in data) {
+                        Object.keys(data).forEach(function(prop) {
                             child.fill(prop, data[prop]);
-                        }
+                        });
                     });
 
                     node.expanded = match;
index fdbf035f0aadaa6a28e73696c6d1c38c51b7e28a..4e20ebbdf661cf0c07fa7e084a60604c57a329b1 100644 (file)
@@ -95,13 +95,6 @@ define(
              * @param reqObj HistoryRequest object to be selected
              */
             function toggleReqSelection(onlyOneSelected, reqObj){
-
-                //self.collections.forEach(function (collection){
-                //    collection.data.forEach(function (req){
-                //        req.selected = reqObj === req;
-                //    });
-                //});
-
                 if (onlyOneSelected){
                     self.selectedItems.forEach(function (req){
                         req.selected = false;
@@ -251,20 +244,17 @@ define(
              * Get expanded collection names
              */
             function getExpandedCollectionNames(){
-                var expandCollectionNames = [];
-                self.collections.forEach(function(collection){
-                    if (collection.expanded) {
-                        expandCollectionNames.push(collection.name);
-                    }
+                return self.collections.filter(function(collection){
+                    return collection.expanded;
+                }).map(function(collection){
+                    return collection.name;
                 });
-                return expandCollectionNames;
             }
 
             /**
              * Expand collections by expandCollectionNames
              */
             function expandCollectionByNames(expandCollectionNames){
-
                 self.collections.forEach(function(collection){
                     if (findName(collection.name)) {
                         collection.expanded = true;
@@ -272,16 +262,10 @@ define(
                 });
 
                 function findName(name) {
-                    var found = false;
-                    expandCollectionNames.forEach(function(collectionName){
-                        if (name === collectionName) {
-                            found = true;
-                            return null;
-                        }
+                    return expandCollectionNames.some(function(collectionName){
+                        return name === collectionName;
                     });
-                    return found;
                 }
-
             }
 
         }