Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit e21ec90

Browse files
authored
feat(base): Annotate mdc-base for closure (#730)
Resolves #331: Annotate mdc-base for closure
1 parent 6c1043e commit e21ec90

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
}
157157
},
158158
"closureWhitelist": [
159-
"mdc-animation"
159+
"mdc-animation",
160+
"mdc-base"
160161
]
161162
}

packages/mdc-base/component.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616

1717
import MDCFoundation from './foundation';
1818

19+
/**
20+
* @template F
21+
*/
1922
export 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') {

packages/mdc-base/foundation.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,45 @@
1414
* limitations under the License.
1515
*/
1616

17+
/**
18+
* @template A
19+
*/
1720
export default class MDCFoundation {
21+
22+
/** @return enum{cssClasses} */
1823
static get cssClasses() {
1924
// Classes extending MDCFoundation should implement this method to return an object which exports every
2025
// CSS class the foundation class needs as a property. e.g. {ACTIVE: 'mdc-component--active'}
2126
return {};
2227
}
2328

29+
/** @return enum{strings} */
2430
static get strings() {
2531
// Classes extending MDCFoundation should implement this method to return an object which exports all
2632
// semantic strings as constants. e.g. {ARIA_ROLE: 'tablist'}
2733
return {};
2834
}
2935

36+
/** @return enum{numbers} */
3037
static get numbers() {
3138
// Classes extending MDCFoundation should implement this method to return an object which exports all
3239
// of its semantic numbers as constants. e.g. {ANIMATION_DELAY_MS: 350}
3340
return {};
3441
}
3542

43+
/** @return {!Object} */
3644
static get defaultAdapter() {
3745
// Classes extending MDCFoundation may choose to implement this getter in order to provide a convenient
3846
// way of viewing the necessary methods of an adapter. In the future, this could also be used for adapter
3947
// validation.
4048
return {};
4149
}
4250

51+
/**
52+
* @param {!A} adapter
53+
*/
4354
constructor(adapter = {}) {
55+
/** @private {!A} */
4456
this.adapter_ = adapter;
4557
}
4658

0 commit comments

Comments
 (0)