From 8fdc8dcabba571946f933123b53edb64e1b3ea7e Mon Sep 17 00:00:00 2001 From: Xaver Maierhofer Date: Sun, 21 Oct 2018 18:30:48 +0200 Subject: [PATCH] [TASK] Avoid unnassary loops in domain name mapping --- .eslintrc | 1 + lib/proportions.js | 3 ++- lib/utils/node.js | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.eslintrc b/.eslintrc index 35fcf81..f1ccc5c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,5 +9,6 @@ rules: "func-names": 0 "guard-for-in": 0 "no-undefined": 0 + "consistent-return": 0 "no-nested-ternary": 0 "no-extend-native": ["error", { "exceptions": ["String"] }] diff --git a/lib/proportions.js b/lib/proportions.js index 12121cb..4d2125a 100644 --- a/lib/proportions.js +++ b/lib/proportions.js @@ -110,9 +110,10 @@ define(['d3-interpolate', 'snabbdom', 'utils/version', 'filters/genericnode', 'h var domainDict = count(nodes, ['domain'], function (d) { if (config.domainNames) { - config.domainNames.forEach(function (t) { + config.domainNames.some(function (t) { if (d === t.domain) { d = t.name; + return true; } }); } diff --git a/lib/utils/node.js b/lib/utils/node.js index f241243..9df5aa8 100644 --- a/lib/utils/node.js +++ b/lib/utils/node.js @@ -71,9 +71,10 @@ define(['snabbdom', 'helper', 'moment'], function (V, helper, moment) { self.showDomain = function showDomain(d) { var rt = d.domain; if (config.domainNames) { - config.domainNames.forEach(function (t) { - if (d.domain === t.domain) { + config.domainNames.some(function (t) { + if (rt === t.domain) { rt = t.name; + return true; } }); }