1616
1717import MDCFoundation from './foundation' ;
1818
19+ /**
20+ * @template F
21+ */
1922export default class MDCComponent {
23+
24+ /**
25+ * @param {!Element } root
26+ * @return {!MDCComponent }
27+ */
2028 static attachTo ( root ) {
2129 // Subclasses which extend MDCBase should provide an attachTo() method that takes a root element and
2230 // 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 {
2533 return new MDCComponent ( root , new MDCFoundation ( ) ) ;
2634 }
2735
36+ /**
37+ * @param {!Element } root
38+ * @param {!F } foundation
39+ * @param {...? } args
40+ */
2841 constructor ( root , foundation = undefined , ...args ) {
42+ /** @private {!Element} */
2943 this . root_ = root ;
3044 this . initialize ( ...args ) ;
3145 // Note that we initialize foundation here and not within the constructor's default param so that
3246 // this.root_ is defined and can be used within the foundation class.
47+ /** @private {!F} */
3348 this . foundation_ = foundation === undefined ? this . getDefaultFoundation ( ) : foundation ;
3449 this . foundation_ . init ( ) ;
3550 this . initialSyncWithDOM ( ) ;
@@ -41,6 +56,9 @@ export default class MDCComponent {
4156 // initialized. Any additional arguments besides root and foundation will be passed in here.
4257 }
4358
59+ /**
60+ * @return {!F } foundation
61+ */
4462 getDefaultFoundation ( ) {
4563 // Subclasses must override this method to return a properly configured foundation class for the
4664 // component.
@@ -61,20 +79,33 @@ export default class MDCComponent {
6179 this . foundation_ . destroy ( ) ;
6280 }
6381
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+ */
6688 listen ( evtType , handler ) {
6789 this . root_ . addEventListener ( evtType , handler ) ;
6890 }
6991
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+ */
7298 unlisten ( evtType , handler ) {
7399 this . root_ . removeEventListener ( evtType , handler ) ;
74100 }
75101
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+ */
78109 emit ( evtType , evtData , shouldBubble = false ) {
79110 let evt ;
80111 if ( typeof CustomEvent === 'function' ) {
0 commit comments