@@ -4,6 +4,9 @@ import { Application } from '../application';
4
4
import { EventDispatcher , Event , EventMap } from './events' ;
5
5
import { DeclarationOption } from './options/declaration' ;
6
6
7
+ /**
8
+ * Exposes a reference to the root Application component.
9
+ */
7
10
export interface ComponentHost {
8
11
readonly application : Application ;
9
12
}
@@ -16,14 +19,21 @@ export interface ComponentClass<T extends Component, O extends ComponentHost = C
16
19
new ( owner : O ) : T ;
17
20
}
18
21
22
+ /**
23
+ * Option-bag passed to Component decorator.
24
+ */
19
25
export interface ComponentOptions {
20
26
name ?: string ;
27
+ /** Specify valid child component class. Used to prove that children are valid via `instanceof` checks */
21
28
childClass ?: Function ;
22
29
internal ?: boolean ;
23
30
}
24
31
25
32
const childMappings : { host : ChildableComponent < any , any > , child : Function } [ ] = [ ] ;
26
33
34
+ /**
35
+ * Class decorator applied to Components
36
+ */
27
37
export function Component ( options : ComponentOptions ) : ClassDecorator {
28
38
return ( target : Function ) => {
29
39
const proto = target . prototype ;
@@ -63,6 +73,11 @@ export function Component(options: ComponentOptions): ClassDecorator {
63
73
} ;
64
74
}
65
75
76
+ /**
77
+ * Decorator that declares a configuration option.
78
+ *
79
+ * Use it on an instance property of a Component class.
80
+ */
66
81
export function Option ( options : DeclarationOption ) : PropertyDecorator {
67
82
return function ( target : object , propertyKey : string | symbol ) {
68
83
if ( ! ( target instanceof AbstractComponent ) ) {
@@ -107,7 +122,10 @@ export class ComponentEvent extends Event {
107
122
export const DUMMY_APPLICATION_OWNER = Symbol ( ) ;
108
123
109
124
/**
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.
111
129
*/
112
130
export abstract class AbstractComponent < O extends ComponentHost > extends EventDispatcher implements ComponentHost {
113
131
/**
@@ -176,7 +194,10 @@ export abstract class AbstractComponent<O extends ComponentHost> extends EventDi
176
194
}
177
195
178
196
/**
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
180
201
*/
181
202
export abstract class ChildableComponent < O extends ComponentHost , C extends Component > extends AbstractComponent < O > {
182
203
/**
0 commit comments