@@ -78,9 +78,9 @@ export default class CustomElementRegistry {
78
78
* but the list of elements is only populated during a flush after which
79
79
* all of the entries are removed. DO NOT edit outside of `#_flush`.
80
80
* @private
81
- * @type {!Map<string, ! Array<!HTMLElement> > }
81
+ * @type {!Array<string > }
82
82
*/
83
- this . _elementsWithPendingDefinitions = new Map ( ) ;
83
+ this . _unflushedLocalNames = [ ] ;
84
84
85
85
/**
86
86
* @private
@@ -102,7 +102,7 @@ export default class CustomElementRegistry {
102
102
this . internal_assertCanDefineLocalName ( localName ) ;
103
103
104
104
this . _localNameToConstructorGetter . set ( localName , constructorGetter ) ;
105
- this . _elementsWithPendingDefinitions . set ( localName , [ ] ) ;
105
+ this . _unflushedLocalNames . push ( localName ) ;
106
106
107
107
// If we've already called the flush callback and it hasn't called back yet,
108
108
// don't call it again.
@@ -124,7 +124,7 @@ export default class CustomElementRegistry {
124
124
this . internal_assertCanDefineLocalName ( localName ) ;
125
125
126
126
this . internal_reifyDefinition ( localName , constructor ) ;
127
- this . _elementsWithPendingDefinitions . set ( localName , [ ] ) ;
127
+ this . _unflushedLocalNames . push ( localName ) ;
128
128
129
129
// If we've already called the flush callback and it hasn't called back yet,
130
130
// don't call it again.
@@ -234,7 +234,11 @@ export default class CustomElementRegistry {
234
234
*/
235
235
const elementsWithStableDefinitions = [ ] ;
236
236
237
- const elementsWithPendingDefinitions = this . _elementsWithPendingDefinitions ;
237
+ const unflushedLocalNames = this . _unflushedLocalNames ;
238
+ const elementsWithPendingDefinitions = new Map ( ) ;
239
+ for ( let i = 0 ; i < unflushedLocalNames . length ; i ++ ) {
240
+ elementsWithPendingDefinitions . set ( unflushedLocalNames [ i ] , [ ] ) ;
241
+ }
238
242
239
243
this . _internals . patchAndUpgradeTree ( document , {
240
244
upgrade : element => {
@@ -262,7 +266,10 @@ export default class CustomElementRegistry {
262
266
}
263
267
264
268
// Upgrade elements with 'pending' definitions in the order they were defined.
265
- elementsWithPendingDefinitions . forEach ( ( pendingUpgradableElements , localName ) => {
269
+ for ( let i = 0 ; i < unflushedLocalNames . length ; i ++ ) {
270
+ const localName = unflushedLocalNames [ i ] ;
271
+ const pendingUpgradableElements = elementsWithPendingDefinitions . get ( localName ) ;
272
+
266
273
// Attempt to upgrade all applicable elements.
267
274
for ( let i = 0 ; i < pendingUpgradableElements . length ; i ++ ) {
268
275
this . _internals . upgradeReaction ( pendingUpgradableElements [ i ] ) ;
@@ -273,9 +280,9 @@ export default class CustomElementRegistry {
273
280
if ( deferred ) {
274
281
deferred . resolve ( undefined ) ;
275
282
}
276
- } ) ;
283
+ }
277
284
278
- elementsWithPendingDefinitions . clear ( ) ;
285
+ unflushedLocalNames . length = 0 ;
279
286
}
280
287
281
288
/**
@@ -319,8 +326,7 @@ export default class CustomElementRegistry {
319
326
// resolved early here even though it might fail later when reified.
320
327
const anyDefinitionExists = this . _localNameToDefinition . has ( localName ) ||
321
328
this . _localNameToConstructorGetter . has ( localName ) ;
322
- const definitionHasFlushed =
323
- ! this . _elementsWithPendingDefinitions . has ( localName ) ;
329
+ const definitionHasFlushed = this . _unflushedLocalNames . indexOf ( localName ) === - 1 ;
324
330
if ( anyDefinitionExists && definitionHasFlushed ) {
325
331
deferred . resolve ( undefined ) ;
326
332
}
0 commit comments