Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
siteUtils => getFolders; Use for() instead of forEach()
Browse files Browse the repository at this point in the history
Auditors: @NejcZdovc
  • Loading branch information
bsclifton committed Jul 11, 2017
1 parent 21e2b13 commit 8d2f527
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions js/state/siteUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,26 +752,30 @@ module.exports.getFolder = function (sites, folderId) {
module.exports.getFolders = function (sites, folderId, parentId, labelPrefix) {
parentId = parentId || 0
let folders = []
sites
const results = sites
.filter(site => {
return (site.get('parentFolderId', 0) === parentId && module.exports.isFolder(site))
})
.toList()
.sort(module.exports.siteSort)
.forEach((site) => {
if (site.get('folderId') === folderId) {
return
}

const label = (labelPrefix || '') + (site.get('customTitle') || site.get('title'))
folders.push({
folderId: site.get('folderId'),
parentFolderId: site.get('parentFolderId'),
label
})
const subsites = module.exports.getFolders(sites, folderId, site.get('folderId'), (label || '') + ' / ')
folders = folders.concat(subsites)
const resultSize = results.size
for (let i = 0; i < resultSize; i++) {
const site = results.get(i)
if (site.get('folderId') === folderId) {
continue
}

const label = (labelPrefix || '') + (site.get('customTitle') || site.get('title'))
folders.push({
folderId: site.get('folderId'),
parentFolderId: site.get('parentFolderId'),
label
})
const subsites = module.exports.getFolders(sites, folderId, site.get('folderId'), (label || '') + ' / ')
folders = folders.concat(subsites)
}

return folders
}

Expand Down

0 comments on commit 8d2f527

Please sign in to comment.