@@ -68,12 +68,12 @@ const standardCustomElement =
68
68
*
69
69
* @param tagName the name of the custom element to define
70
70
*/
71
- export const customElement = ( tagName : string ) => (
72
- classOrDescriptor : Constructor < HTMLElement > | ClassDescriptor ) =>
73
- ( typeof classOrDescriptor === 'function' )
74
- ? legacyCustomElement ( tagName ,
75
- classOrDescriptor as Constructor < HTMLElement > )
76
- : standardCustomElement ( tagName , classOrDescriptor as ClassDescriptor ) ;
71
+ export const customElement = ( tagName : string ) =>
72
+ ( classOrDescriptor : Constructor < HTMLElement > | ClassDescriptor ) =>
73
+ ( typeof classOrDescriptor === 'function' ) ?
74
+ legacyCustomElement (
75
+ tagName , classOrDescriptor as Constructor < HTMLElement > ) :
76
+ standardCustomElement ( tagName , classOrDescriptor as ClassDescriptor ) ;
77
77
78
78
const standardProperty =
79
79
( options : PropertyDeclaration , element : ClassElement ) => {
@@ -93,10 +93,10 @@ const standardProperty =
93
93
// must return some kind of descriptor, so return a descriptor for an
94
94
// unused prototype field. The finisher calls createProperty().
95
95
return {
96
- kind : 'field' ,
97
- key : Symbol ( ) ,
98
- placement : 'own' ,
99
- descriptor : { } ,
96
+ kind : 'field' ,
97
+ key : Symbol ( ) ,
98
+ placement : 'own' ,
99
+ descriptor : { } ,
100
100
// When @babel /plugin-proposal-decorators implements initializers,
101
101
// do this instead of the initializer below. See:
102
102
// https://github.com/babel/babel/issues/9260 extras: [
@@ -118,10 +118,11 @@ const standardProperty =
118
118
}
119
119
} ;
120
120
121
- const legacyProperty = ( options : PropertyDeclaration , proto : Object ,
122
- name : PropertyKey ) => {
123
- ( proto . constructor as typeof UpdatingElement ) . createProperty ( name ! , options ) ;
124
- } ;
121
+ const legacyProperty =
122
+ ( options : PropertyDeclaration , proto : Object , name : PropertyKey ) => {
123
+ ( proto . constructor as typeof UpdatingElement )
124
+ . createProperty ( name ! , options ) ;
125
+ } ;
125
126
126
127
/**
127
128
* A property decorator which creates a LitElement property which reflects a
@@ -132,35 +133,36 @@ const legacyProperty = (options: PropertyDeclaration, proto: Object,
132
133
*/
133
134
export function property ( options ?: PropertyDeclaration ) {
134
135
return ( protoOrDescriptor : Object | ClassElement , name ?: PropertyKey ) : any =>
135
- ( name !== undefined )
136
- ? legacyProperty ( options ! , protoOrDescriptor as Object , name )
137
- : standardProperty ( options ! ,
138
- protoOrDescriptor as ClassElement ) ;
136
+ ( name !== undefined ) ?
137
+ legacyProperty ( options ! , protoOrDescriptor as Object , name ) :
138
+ standardProperty ( options ! , protoOrDescriptor as ClassElement ) ;
139
139
}
140
140
141
141
/**
142
142
* A property decorator that converts a class property into a getter that
143
143
* executes a querySelector on the element's renderRoot.
144
144
*/
145
- export const query = _query ( ( target : NodeSelector , selector : string ) =>
146
- target . querySelector ( selector ) ) ;
145
+ export const query = _query (
146
+ ( target : NodeSelector , selector : string ) => target . querySelector ( selector ) ) ;
147
147
148
148
/**
149
149
* A property decorator that converts a class property into a getter
150
150
* that executes a querySelectorAll on the element's renderRoot.
151
151
*/
152
- export const queryAll = _query ( ( target : NodeSelector , selector : string ) =>
153
- target . querySelectorAll ( selector ) ) ;
152
+ export const queryAll = _query (
153
+ ( target : NodeSelector , selector : string ) =>
154
+ target . querySelectorAll ( selector ) ) ;
154
155
155
156
const legacyQuery =
156
- ( descriptor : PropertyDescriptor , proto : Object ,
157
- name : PropertyKey ) => { Object . defineProperty ( proto , name , descriptor ) ; } ;
157
+ ( descriptor : PropertyDescriptor , proto : Object , name : PropertyKey ) => {
158
+ Object . defineProperty ( proto , name , descriptor ) ;
159
+ } ;
158
160
159
161
const standardQuery = ( descriptor : PropertyDescriptor , element : ClassElement ) =>
160
162
( {
161
- kind : 'method' ,
162
- placement : 'prototype' ,
163
- key : element . key ,
163
+ kind : 'method' ,
164
+ placement : 'prototype' ,
165
+ key : element . key ,
164
166
descriptor,
165
167
} ) ;
166
168
@@ -173,33 +175,37 @@ const standardQuery = (descriptor: PropertyDescriptor, element: ClassElement) =>
173
175
* element.
174
176
*/
175
177
function _query < T > ( queryFn : ( target : NodeSelector , selector : string ) => T ) {
176
- return ( selector : string ) => ( protoOrDescriptor : Object | ClassElement ,
177
- name ?: PropertyKey ) : any => {
178
- const descriptor = {
179
- get ( this : LitElement ) { return queryFn ( this . renderRoot ! , selector ) ; } ,
180
- enumerable : true ,
181
- configurable : true ,
182
- } ;
183
- return ( name !== undefined )
184
- ? legacyQuery ( descriptor , protoOrDescriptor as Object , name )
185
- : standardQuery ( descriptor , protoOrDescriptor as ClassElement ) ;
186
- } ;
178
+ return ( selector : string ) =>
179
+ ( protoOrDescriptor : Object | ClassElement ,
180
+ name ?: PropertyKey ) : any => {
181
+ const descriptor = {
182
+ get ( this : LitElement ) {
183
+ return queryFn ( this . renderRoot ! , selector ) ;
184
+ } ,
185
+ enumerable : true ,
186
+ configurable : true ,
187
+ } ;
188
+ return ( name !== undefined ) ?
189
+ legacyQuery ( descriptor , protoOrDescriptor as Object , name ) :
190
+ standardQuery ( descriptor , protoOrDescriptor as ClassElement ) ;
191
+ } ;
187
192
}
188
193
189
194
const standardEventOptions =
190
195
( options : AddEventListenerOptions , element : ClassElement ) => {
191
196
return {
192
197
...element ,
193
198
finisher ( clazz : typeof UpdatingElement ) {
194
- Object . assign ( clazz . prototype [ element . key as keyof UpdatingElement ] ,
195
- options ) ;
199
+ Object . assign (
200
+ clazz . prototype [ element . key as keyof UpdatingElement ] , options ) ;
196
201
}
197
202
} ;
198
203
} ;
199
204
200
205
const legacyEventOptions =
201
- ( options : AddEventListenerOptions , proto : any ,
202
- name : PropertyKey ) => { Object . assign ( proto [ name ] , options ) ; } ;
206
+ ( options : AddEventListenerOptions , proto : any , name : PropertyKey ) => {
207
+ Object . assign ( proto [ name ] , options ) ;
208
+ } ;
203
209
204
210
/**
205
211
* Adds event listener options to a method used as an event listener in a
@@ -234,7 +240,7 @@ export const eventOptions = (options: AddEventListenerOptions) =>
234
240
// TODO(kschaaf): unclear why it was only failing on this decorator and not
235
241
// the others
236
242
( ( protoOrDescriptor : Object | ClassElement , name ?: string ) =>
237
- ( name !== undefined )
238
- ? legacyEventOptions ( options , protoOrDescriptor as Object , name )
239
- : standardEventOptions ( options ,
240
- protoOrDescriptor as ClassElement ) ) as any ;
243
+ ( name !== undefined ) ?
244
+ legacyEventOptions ( options , protoOrDescriptor as Object , name ) :
245
+ standardEventOptions ( options , protoOrDescriptor as ClassElement ) ) as
246
+ any ;
0 commit comments