@@ -64,12 +64,15 @@ export class Attributes {
64
64
const ids = {
65
65
$ : 'document-querySelector' ,
66
66
el : `proxyWindow['${ this . base . id } ${ State . DISABLE_RE_RENDER_KEY } ']` ,
67
+ group : this . base . group
68
+ ? `proxyWindow['${ this . base . group . id } ${
69
+ ! options . isGroup ? State . DISABLE_RE_RENDER_KEY : ''
70
+ } ']`
71
+ : undefined ,
72
+ ...( options . ids || { } ) ,
67
73
// "this" is set under the interpreter as bind context
68
74
}
69
75
70
- if ( this . base . group )
71
- ids . group = `proxyWindow['${ this . base . group . id } ${ State . DISABLE_RE_RENDER_KEY } ']`
72
-
73
76
engine . replace ( ids )
74
77
75
78
// window variables are used instead of proxy window
@@ -93,7 +96,7 @@ export class Attributes {
93
96
94
97
async evaluateAttribute ( attr ) {
95
98
if ( ! Attributes . isValidAttribute ( attr , this . base . element ) ) return
96
- if ( attr === ':group' ) this . evaluateGroup ( )
99
+ if ( attr === ':group' ) await this . evaluateGroup ( )
97
100
else if ( attr === ':class' ) await this . evaluateClass ( )
98
101
else if ( attr === ':text' ) await this . evaluateText ( )
99
102
else if ( attr === ':value' ) await this . evaluateValue ( )
@@ -131,10 +134,31 @@ export class Attributes {
131
134
} )
132
135
}
133
136
134
- evaluateGroup ( ) {
135
- if ( ! this . base . element . hasAttribute ( ':group' ) ) return
136
- if ( this . base . isGroup ( ) ) return
137
- this . base . setAsGroup ( )
137
+ /*
138
+ :group is a special attribute that acts as an :load event
139
+ when it has a given expr. Unlike other attributes, state updates
140
+ inside :group will trigger re-renders.
141
+
142
+ NOTE: This should NOT be used in this.evaluate() because it will
143
+ trigger an infinite loop.
144
+ */
145
+ async evaluateGroup ( ) {
146
+ if ( ! this . base . isGroup ( ) ) return
147
+
148
+ const expr = this . base . element . getAttribute ( ':group' )
149
+ if ( ! expr ) return
150
+
151
+ const ids = { }
152
+
153
+ this . base . groupVariables . forEach ( ( variable ) => {
154
+ ids [ variable ] = `proxyWindow['${ this . base . id } '].${ variable } `
155
+ } )
156
+
157
+ try {
158
+ await this . _interpret ( expr , { isGroup : true , ids } )
159
+ } catch ( error ) {
160
+ this . _handleError ( ':group' , expr , error )
161
+ }
138
162
}
139
163
140
164
async evaluateClass ( ) {
0 commit comments