File tree 2 files changed +21
-29
lines changed
src/StimulusBundle/assets
2 files changed +21
-29
lines changed Original file line number Diff line number Diff line change @@ -53,22 +53,17 @@ class StimulusLazyControllerHandler {
53
53
return ;
54
54
}
55
55
new MutationObserver ( ( mutationsList ) => {
56
- for ( const mutation of mutationsList ) {
57
- switch ( mutation . type ) {
58
- case 'childList' : {
59
- for ( const node of mutation . addedNodes ) {
60
- if ( node instanceof Element ) {
61
- extractControllerNamesFrom ( node ) . forEach ( ( controllerName ) => {
62
- this . loadLazyController ( controllerName ) ;
63
- } ) ;
64
- }
56
+ for ( const { attributeName, target, type } of mutationsList ) {
57
+ switch ( type ) {
58
+ case 'attributes' : {
59
+ if ( attributeName === controllerAttribute &&
60
+ target . getAttribute ( controllerAttribute ) ) {
61
+ extractControllerNamesFrom ( target ) . forEach ( ( controllerName ) => this . loadLazyController ( controllerName ) ) ;
65
62
}
66
63
break ;
67
64
}
68
- case 'attributes' : {
69
- if ( mutation . attributeName === controllerAttribute ) {
70
- extractControllerNamesFrom ( mutation . target ) . forEach ( ( controllerName ) => this . loadLazyController ( controllerName ) ) ;
71
- }
65
+ case 'childList' : {
66
+ this . lazyLoadExistingControllers ( target ) ;
72
67
}
73
68
}
74
69
}
Original file line number Diff line number Diff line change @@ -99,26 +99,23 @@ class StimulusLazyControllerHandler {
99
99
return ;
100
100
}
101
101
new MutationObserver ( ( mutationsList ) => {
102
- for ( const mutation of mutationsList ) {
103
- switch ( mutation . type ) {
104
- case 'childList' : {
105
- // @ts -ignore
106
- for ( const node of mutation . addedNodes ) {
107
- if ( node instanceof Element ) {
108
- extractControllerNamesFrom ( node ) . forEach ( ( controllerName ) => {
109
- this . loadLazyController ( controllerName ) ;
110
- } ) ;
111
- }
112
- }
113
- break ;
114
- }
115
-
102
+ for ( const { attributeName, target, type } of mutationsList ) {
103
+ switch ( type ) {
116
104
case 'attributes' : {
117
- if ( mutation . attributeName === controllerAttribute ) {
118
- extractControllerNamesFrom ( mutation . target as Element ) . forEach ( ( controllerName ) =>
105
+ if (
106
+ attributeName === controllerAttribute &&
107
+ ( target as Element ) . getAttribute ( controllerAttribute )
108
+ ) {
109
+ extractControllerNamesFrom ( target as Element ) . forEach ( ( controllerName ) =>
119
110
this . loadLazyController ( controllerName )
120
111
) ;
121
112
}
113
+
114
+ break ;
115
+ }
116
+
117
+ case 'childList' : {
118
+ this . lazyLoadExistingControllers ( target as Element ) ;
122
119
}
123
120
}
124
121
}
You can’t perform that action at this time.
0 commit comments