16
16
17
17
import MDCFoundation from './foundation' ;
18
18
19
+ /**
20
+ * @template F
21
+ */
19
22
export default class MDCComponent {
23
+
24
+ /**
25
+ * @param {!Element } root
26
+ * @return {!MDCComponent }
27
+ */
20
28
static attachTo ( root ) {
21
29
// Subclasses which extend MDCBase should provide an attachTo() method that takes a root element and
22
30
// returns an instantiated component with its root set to that element. Also note that in the cases of
@@ -25,11 +33,18 @@ export default class MDCComponent {
25
33
return new MDCComponent ( root , new MDCFoundation ( ) ) ;
26
34
}
27
35
36
+ /**
37
+ * @param {!Element } root
38
+ * @param {!F } foundation
39
+ * @param {...? } args
40
+ */
28
41
constructor ( root , foundation = undefined , ...args ) {
42
+ /** @private {!Element} */
29
43
this . root_ = root ;
30
44
this . initialize ( ...args ) ;
31
45
// Note that we initialize foundation here and not within the constructor's default param so that
32
46
// this.root_ is defined and can be used within the foundation class.
47
+ /** @private {!F} */
33
48
this . foundation_ = foundation === undefined ? this . getDefaultFoundation ( ) : foundation ;
34
49
this . foundation_ . init ( ) ;
35
50
this . initialSyncWithDOM ( ) ;
@@ -41,6 +56,9 @@ export default class MDCComponent {
41
56
// initialized. Any additional arguments besides root and foundation will be passed in here.
42
57
}
43
58
59
+ /**
60
+ * @return {!F } foundation
61
+ */
44
62
getDefaultFoundation ( ) {
45
63
// Subclasses must override this method to return a properly configured foundation class for the
46
64
// component.
@@ -61,20 +79,33 @@ export default class MDCComponent {
61
79
this . foundation_ . destroy ( ) ;
62
80
}
63
81
64
- // Wrapper method to add an event listener to the component's root element. This is most useful when
65
- // listening for custom events.
82
+ /**
83
+ * Wrapper method to add an event listener to the component's root element. This is most useful when
84
+ * listening for custom events.
85
+ * @param {string } evtType
86
+ * @param {!Function } handler
87
+ */
66
88
listen ( evtType , handler ) {
67
89
this . root_ . addEventListener ( evtType , handler ) ;
68
90
}
69
91
70
- // Wrapper method to remove an event listener to the component's root element. This is most useful when
71
- // unlistening for custom events.
92
+ /**
93
+ * Wrapper method to remove an event listener to the component's root element. This is most useful when
94
+ * unlistening for custom events.
95
+ * @param {string } evtType
96
+ * @param {!Function } handler
97
+ */
72
98
unlisten ( evtType , handler ) {
73
99
this . root_ . removeEventListener ( evtType , handler ) ;
74
100
}
75
101
76
- // Fires a cross-browser-compatible custom event from the component root of the given type,
77
- // with the given data.
102
+ /**
103
+ * Fires a cross-browser-compatible custom event from the component root of the given type,
104
+ * with the given data.
105
+ * @param {string } evtType
106
+ * @param {!Object } evtData
107
+ * @param {boolean } shouldBubble
108
+ */
78
109
emit ( evtType , evtData , shouldBubble = false ) {
79
110
let evt ;
80
111
if ( typeof CustomEvent === 'function' ) {
0 commit comments