File tree 2 files changed +18
-11
lines changed
2 files changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -439,13 +439,19 @@ export default class Entity {
439
439
440
440
dispose ( ) {
441
441
const elements = [ this . element , ...this . element . querySelectorAll ( '*' ) ]
442
+ const variables = [ ]
442
443
443
444
// Remove event bindings
444
445
for ( const element of elements ) {
446
+ if ( element . nodeType !== 1 ) continue
447
+
445
448
const entity = MiniJS . elements . find (
446
449
( entity ) => entity . element === element
447
450
)
448
- entity ?. removeEventBindings ( )
451
+ if ( ! entity ) continue
452
+
453
+ variables . push ( ...entity . variables )
454
+ entity . removeEventBindings ( )
449
455
}
450
456
451
457
// Remove disposed elements
@@ -459,11 +465,13 @@ export default class Entity {
459
465
[ ]
460
466
)
461
467
462
- const unusedVariables = MiniJS . variables . filter (
468
+ const unusedVariables = variables . filter (
463
469
( variable ) => ! usedVariables . includes ( variable )
464
470
)
465
471
466
- MiniJS . variables = [ ...usedVariables ]
472
+ MiniJS . variables = MiniJS . variables . filter (
473
+ ( variable ) => ! unusedVariables . includes ( variable )
474
+ )
467
475
468
476
unusedVariables . forEach ( ( variable ) => {
469
477
if ( variable . startsWith ( 'el.' ) ) {
Original file line number Diff line number Diff line change @@ -120,18 +120,17 @@ const MiniJS = (() => {
120
120
observeDOM ( document . body , ( mutation ) => {
121
121
mutation . forEach ( ( record ) => {
122
122
record . removedNodes . forEach ( ( node ) => {
123
+ if ( node . nodeType !== 1 ) return
123
124
const entity = _elements . find ( ( entity ) => entity . element === node )
124
125
entity ?. dispose ( )
125
126
} )
126
127
127
- if ( record . addedNodes . length ) {
128
- record . addedNodes . forEach ( ( node ) => {
129
- if ( node . nodeType !== 1 ) return
130
- const entity = new Entity ( node )
131
- entity . init ( )
132
- entity . initChildren ( )
133
- } )
134
- }
128
+ record . addedNodes . forEach ( ( node ) => {
129
+ if ( node . nodeType !== 1 ) return
130
+ const entity = new Entity ( node )
131
+ entity . init ( )
132
+ entity . initChildren ( )
133
+ } )
135
134
} )
136
135
} )
137
136
}
You can’t perform that action at this time.
0 commit comments