Skip to content

Commit

Permalink
Small refactor to fix creating children of reflections
Browse files Browse the repository at this point in the history
  • Loading branch information
alalonde authored and Gerrit0 committed Jan 15, 2020
1 parent 5ec837a commit 52fa7fa
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/lib/output/themes/DefaultTheme.ts
Expand Up @@ -392,43 +392,24 @@ export class NavigationBuilder {
if (modules.length < 10) {
this.buildGroups(modules, root);
} else {
this.buildGroups(this.entryPoint.getChildrenByKind(ReflectionKind.SomeModule), root, this.buildChildren);
this.buildGroups(this.entryPoint.getChildrenByKind(ReflectionKind.SomeModule), root, true);
}

return root;
}

/**
* Create navigation nodes for all container children of the given reflection.
*
* @param reflection The reflection whose children modules should be transformed into navigation nodes.
* @param parent The parent NavigationItem of the newly created nodes.
*/
protected buildChildren(reflection: DeclarationReflection, parent: NavigationItem) {
const modules = reflection.getChildrenByKind(ReflectionKind.SomeModule);
modules.sort((a: DeclarationReflection, b: DeclarationReflection) => {
return a.getFullName() < b.getFullName() ? -1 : 1;
});

modules.forEach((reflection) => {
const item = NavigationItem.create(reflection, parent);
this.includeDedicatedUrls(reflection, item);
this.buildChildren(reflection, item);
});
}

/**
* Create navigation nodes for the given list of reflections. The resulting nodes will be grouped into
* an "internal" and an "external" section when applicable.
*
* @param reflections The list of reflections which should be transformed into navigation nodes.
* @param parent The parent NavigationItem of the newly created nodes.
* @param callback Optional callback invoked for each generated node.
* @param buildChildren Whether navigation nodes should also be built for the children of each reflection.
*/
protected buildGroups(
reflections: DeclarationReflection[],
parent: NavigationItem,
callback?: (reflection: DeclarationReflection, item: NavigationItem) => void
buildChildren: boolean = false
) {
let state = -1;
const hasExternals = this.containsExternals(reflections);
Expand All @@ -445,12 +426,31 @@ export class NavigationBuilder {

const item = NavigationItem.create(reflection, parent);
this.includeDedicatedUrls(reflection, item);
if (callback) {
callback(reflection, item);
if (buildChildren) {
this.buildChildren(reflection, item);
}
});
}

/**
* Create navigation nodes for all container children of the given reflection.
*
* @param reflection The reflection whose children modules should be transformed into navigation nodes.
* @param parent The parent NavigationItem of the newly created nodes.
*/
protected buildChildren(reflection: DeclarationReflection, parent: NavigationItem) {
const modules = reflection.getChildrenByKind(ReflectionKind.SomeModule);
modules.sort((a: DeclarationReflection, b: DeclarationReflection) => {
return a.getFullName() < b.getFullName() ? -1 : 1;
});

modules.forEach((reflection) => {
const item = NavigationItem.create(reflection, parent);
this.includeDedicatedUrls(reflection, item);
this.buildChildren(reflection, item);
});
}

/**
* Test whether the given list of modules contains an external module.
*
Expand Down

0 comments on commit 52fa7fa

Please sign in to comment.