Commit 127f29c4 authored by mo khan's avatar mo khan

Move increment operation to visitor

parent 229681b7
...@@ -16,12 +16,11 @@ class V2Report { ...@@ -16,12 +16,11 @@ class V2Report {
}; };
} }
combine(licenses) { combine(licenses, visitor) {
return licenses.reduce( return licenses.reduce(
(memo, licenseId) => { (memo, licenseId) => {
const license = this.licenseMap[licenseId]; const license = this.licenseMap[licenseId];
this.incrementCountFor(license.name); visitor(license);
if (memo.name === null) { if (memo.name === null) {
return { return {
name: license.name, name: license.name,
...@@ -35,13 +34,17 @@ class V2Report { ...@@ -35,13 +34,17 @@ class V2Report {
} }
incrementCountFor(licenseName) { incrementCountFor(licenseName) {
const legacyLicense = this.licenses.find(license => license.name === licenseName); const license = this.licenses.find(license => license.name === licenseName);
if (legacyLicense) legacyLicense.count += 1; if (license) license.count += 1;
} }
mapFromDependency(dependency) { mapFromDependency(dependency) {
const combinedLicense = this.combine(dependency.licenses, license => {
this.incrementCountFor(license.name);
});
return { return {
license: this.combine(dependency.licenses), license: combinedLicense,
dependency: { dependency: {
name: dependency.name, name: dependency.name,
url: dependency.url, url: dependency.url,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment