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

Commit 19955bf

Browse files
blikblumkfranqueiro
authored andcommittedJul 17, 2018
feat(auto-init): return initialized components (#1333)
1 parent 608e46a commit 19955bf

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed
 

‎packages/mdc-auto-init/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function _emit(evtType, evtData, shouldBubble = false) {
3737
* Auto-initializes all mdc components on a page.
3838
*/
3939
export default function mdcAutoInit(root = document, warn = CONSOLE_WARN) {
40+
const components = [];
4041
const nodes = root.querySelectorAll('[data-mdc-auto-init]');
4142
for (let i = 0, node; (node = nodes[i]); i++) {
4243
const ctorName = node.dataset.mdcAutoInit;
@@ -63,9 +64,11 @@ export default function mdcAutoInit(root = document, warn = CONSOLE_WARN) {
6364
enumerable: false,
6465
configurable: true,
6566
});
67+
components.push(component);
6668
}
6769

6870
_emit('MDCAutoInit:End', {});
71+
return components;
6972
}
7073

7174
mdcAutoInit.register = function(componentName, Ctor, warn = CONSOLE_WARN) {

‎test/unit/mdc-auto-init/mdc-auto-init.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,11 @@ test('#dispatches a MDCAutoInit:End event when all components are initialized -
138138
assert.isOk(evt !== null);
139139
assert.equal(evt.type, type);
140140
});
141+
142+
test('#returns the initialized components', () => {
143+
const root = setupTest();
144+
const components = mdcAutoInit(root);
145+
146+
assert.equal(components.length, 1);
147+
assert.isOk(components[0] instanceof FakeComponent);
148+
});

0 commit comments

Comments
 (0)
This repository has been archived.