Skip to content

Commit e650aa7

Browse files
cspotcodeGerrit0
authored andcommitted
Adds/improves tsdoc comments on a lot of core classes (#915)
1 parent f6ef9ca commit e650aa7

File tree

12 files changed

+73
-5
lines changed

12 files changed

+73
-5
lines changed

src/lib/utils/__events.ts

Whitespace-only changes.

src/lib/utils/component.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { Application } from '../application';
44
import { EventDispatcher, Event, EventMap } from './events';
55
import { DeclarationOption } from './options/declaration';
66

7+
/**
8+
* Exposes a reference to the root Application component.
9+
*/
710
export interface ComponentHost {
811
readonly application: Application;
912
}
@@ -16,14 +19,21 @@ export interface ComponentClass<T extends Component, O extends ComponentHost = C
1619
new(owner: O): T;
1720
}
1821

22+
/**
23+
* Option-bag passed to Component decorator.
24+
*/
1925
export interface ComponentOptions {
2026
name?: string;
27+
/** Specify valid child component class. Used to prove that children are valid via `instanceof` checks */
2128
childClass?: Function;
2229
internal?: boolean;
2330
}
2431

2532
const childMappings: {host: ChildableComponent<any, any>, child: Function}[] = [];
2633

34+
/**
35+
* Class decorator applied to Components
36+
*/
2737
export function Component(options: ComponentOptions): ClassDecorator {
2838
return (target: Function) => {
2939
const proto = target.prototype;
@@ -63,6 +73,11 @@ export function Component(options: ComponentOptions): ClassDecorator {
6373
};
6474
}
6575

76+
/**
77+
* Decorator that declares a configuration option.
78+
*
79+
* Use it on an instance property of a Component class.
80+
*/
6681
export function Option(options: DeclarationOption): PropertyDecorator {
6782
return function(target: object, propertyKey: string | symbol) {
6883
if (!(target instanceof AbstractComponent)) {
@@ -107,7 +122,10 @@ export class ComponentEvent extends Event {
107122
export const DUMMY_APPLICATION_OWNER = Symbol();
108123

109124
/**
110-
* Component base class.
125+
* Component base class. Has an owner (unless it's the application root component),
126+
* can dispatch events to its children, and has access to the root Application component.
127+
*
128+
* @template O type of component's owner.
111129
*/
112130
export abstract class AbstractComponent<O extends ComponentHost> extends EventDispatcher implements ComponentHost {
113131
/**
@@ -176,7 +194,10 @@ export abstract class AbstractComponent<O extends ComponentHost> extends EventDi
176194
}
177195

178196
/**
179-
* Component base class.
197+
* Component that can have child components.
198+
*
199+
* @template O type of Component's owner
200+
* @template C type of Component's children
180201
*/
181202
export abstract class ChildableComponent<O extends ComponentHost, C extends Component> extends AbstractComponent<O> {
182203
/**

src/lib/utils/loggers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export enum LogLevel {
1515
/**
1616
* A logger that will not produce any output.
1717
*
18-
* This logger also serves as the ase calls of other loggers as it implements
18+
* This logger also serves as the base class of other loggers as it implements
1919
* all the required utility functions.
2020
*/
2121
export class Logger {

src/lib/utils/options/declaration.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export enum ParameterScope {
2020
}
2121

2222
/**
23+
* Option-bag passed to Option decorator.
24+
*
2325
* TODO: This should be a union type of multiple possible option types.
2426
*/
2527
export interface DeclarationOption {
@@ -36,6 +38,10 @@ export interface DeclarationOption {
3638
convert?: (param: OptionDeclaration, value?: any) => any;
3739
}
3840

41+
/**
42+
* Runtime structure describing a configuration option.
43+
* Used by option parsing and validation.
44+
*/
3945
export class OptionDeclaration {
4046
name!: string;
4147

src/lib/utils/options/options.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import { Component, AbstractComponent, ChildableComponent } from '../component';
77
import { Application } from '../../application';
88
import { OptionDeclaration, DeclarationOption, ParameterScope } from './declaration';
99

10+
/**
11+
* Child of the master Options component. Options === configuration
12+
*
13+
* Serves one of two roles:
14+
*
15+
* - Aggregates and contributes configuration declarations declared by components or plugins
16+
* - Parses option values from various sources (config file, command-line args, etc)
17+
*/
1018
export class OptionsComponent extends AbstractComponent<Options> { }
1119

1220
export enum OptionsReadMode {
@@ -51,6 +59,10 @@ export class DiscoverEvent extends Event {
5159
}
5260
}
5361

62+
/**
63+
* Responsible for loading options via child components that read options
64+
* from various sources.
65+
*/
5466
@Component({name: 'options', internal: true, childClass: OptionsComponent})
5567
export class Options extends ChildableComponent<Application, OptionsComponent> {
5668
private declarations!: {[name: string]: OptionDeclaration};

src/lib/utils/options/readers/arguments.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { Component } from '../../component';
55
import { DiscoverEvent, OptionsComponent } from '../options';
66
import { ParameterType } from '../declaration';
77

8+
/**
9+
* Obtains option values from command-line arguments
10+
*/
811
@Component({name: 'options:arguments'})
912
export class ArgumentsReader extends OptionsComponent {
1013
initialize() {

src/lib/utils/options/readers/tsconfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { OptionsComponent, OptionsReadMode, DiscoverEvent } from '../options';
88
import { ParameterType, ParameterHint } from '../declaration';
99
import { TypeScriptSource } from '../sources/typescript';
1010

11+
/**
12+
* Obtains option values from tsconfig.json
13+
*/
1114
@Component({name: 'options:tsconfig'})
1215
export class TSConfigReader extends OptionsComponent {
1316
@Option({

src/lib/utils/options/readers/typedoc.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { Component, Option } from '../../component';
66
import { OptionsComponent, OptionsReadMode, DiscoverEvent } from '../options';
77
import { ParameterType, ParameterHint } from '../declaration';
88

9+
/**
10+
* Obtains option values from typedoc.js
11+
*/
912
@Component({name: 'options:typedoc'})
1013
export class TypedocReader extends OptionsComponent {
1114
@Option({

src/lib/utils/options/sources/component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { Component, ComponentEvent, AbstractComponent, ChildableComponent } from '../../component';
22
import { OptionsComponent } from '../options';
33

4+
/**
5+
* Aggregates options declared by other components.
6+
*
7+
* Listens for when a component is added and adds the component's declared
8+
* options to the `Options` component.
9+
*/
410
@Component({name: 'options:component'})
511
export class ComponentSource extends OptionsComponent {
612
private knownComponents!: string[];

src/lib/utils/options/sources/typescript.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import { Component } from '../../component';
55
import { OptionsComponent } from '../options';
66
import { DeclarationOption, ParameterScope, ParameterType, ParameterHint } from '../declaration';
77

8+
/**
9+
* Discovers and contributes options declared by TypeScript.
10+
*
11+
* typedoc accepts many of the same options as TypeScript itself, so they must be parsed
12+
* from TypeScript's metadata and declared on typedoc's Option parser.
13+
*/
814
@Component({name: 'options:typescript'})
915
export class TypeScriptSource extends OptionsComponent {
1016
private declarations!: DeclarationOption[];

src/lib/utils/paths.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import { Minimatch, IMinimatch } from 'minimatch';
33

44
const unix = Path.sep === '/';
55

6+
/**
7+
* Convert array of glob patterns to array of minimatch instances.
8+
*
9+
* Handle a few Windows-Unix path gotchas.
10+
*/
611
export function createMinimatch(patterns: string[]): IMinimatch[] {
712
return patterns.map((pattern: string): IMinimatch => {
8-
// Ensure correct pathing on unix, by transforming `\` to `/` and remvoing any `X:/` fromt he path
13+
// Ensure correct pathing on unix, by transforming `\` to `/` and removing any `X:/` from the path
914
if (unix) { pattern = pattern.replace(/[\\]/g, '/').replace(/^\w:/, ''); }
1015

1116
// pattern paths not starting with '**' are resolved even if it is an
@@ -17,7 +22,7 @@ export function createMinimatch(patterns: string[]): IMinimatch[] {
1722
// On Windows we transform `\` to `/` to unify the way paths are intepreted
1823
if (!unix) { pattern = pattern.replace(/[\\]/g, '/'); }
1924

20-
// Unify the path slashes before creating the minimatch, for more relyable matching
25+
// Unify the path slashes before creating the minimatch, for more reliable matching
2126
return new Minimatch(pattern, { dot: true });
2227
});
2328
}

src/lib/utils/plugins.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { Application } from '../application';
55
import { AbstractComponent, Component, Option } from './component';
66
import { ParameterType } from './options/declaration';
77

8+
/**
9+
* Responsible for discovering and loading plugins.
10+
*/
811
@Component({ name: 'plugin-host', internal: true })
912
export class PluginHost extends AbstractComponent<Application> {
1013
@Option({

0 commit comments

Comments
 (0)