Skip to content

Commit 66f0af7

Browse files
author
Daniel Morse
committed
fix: replace individual 'rendered' event listeners with Promise waiting for 'ready'
1 parent bc95448 commit 66f0af7

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

packages/components/bolt-accordion/src/accordion.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,21 @@ class BoltAccordion extends withContext(withLitHtml()) {
204204
// Array passed to the Accordion plugin, a series of trigger/content pairs
205205
this.accordionItems = [];
206206

207-
this.accordionItemElements.forEach(item => {
208-
const onItemReady = e => {
209-
if (e.detail.name !== 'bolt-accordion-item') return;
210-
this.handleAccordionItemReady(item);
211-
item.removeEventListener('rendered', onItemReady);
212-
};
213-
214-
if (item._wasInitiallyRendered || this._wasMutated) {
207+
Promise.all(
208+
this.accordionItemElements.map(item => {
209+
if (item._wasInitiallyRendered || this._wasMutated) return;
210+
return new Promise((resolve, reject) => {
211+
item.addEventListener('ready', e => {
212+
return item === e.target && resolve();
213+
});
214+
item.addEventListener('error', reject);
215+
});
216+
}),
217+
).then(() => {
218+
this.accordionItemElements.forEach(item => {
215219
this.handleAccordionItemReady(item);
216-
this._wasMutated = false;
217-
} else {
218-
item.addEventListener('rendered', onItemReady);
219-
}
220+
});
221+
this._wasMutated = false;
220222
});
221223
}
222224

0 commit comments

Comments
 (0)