File tree Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -321,17 +321,19 @@ export function observer<T extends AnyFn>(
321
321
322
322
function action2023 ( args : Parameters < Decorator > ) {
323
323
const dec = identifyModernDecoratorArgs ( args ) ;
324
- switch ( dec . kind ) {
325
- case 'method' :
326
- dec . context . addInitializer ( function ( this : any ) {
327
- Object . defineProperty (
328
- this ,
329
- dec . context . name ,
330
- setupAction ( this , dec . context . name , dec . value )
331
- ) ;
332
- } ) ;
333
- break ;
334
- default :
335
- throw new Error ( `unimplemented: action on ${ dec . kind } ${ dec . context . name ?. toString ( ) } ` ) ;
336
- }
324
+ assert (
325
+ 'The @action decorator must be applied to methods when used in native classes' ,
326
+ dec . kind === 'method'
327
+ ) ;
328
+ let needsSetup = true ;
329
+ dec . context . addInitializer ( function ( this : any ) {
330
+ if ( needsSetup ) {
331
+ Object . defineProperty (
332
+ this . constructor . prototype ,
333
+ dec . context . name ,
334
+ setupAction ( this . constructor . prototype , dec . context . name , dec . value )
335
+ ) ;
336
+ needsSetup = false ;
337
+ }
338
+ } ) ;
337
339
}
You can’t perform that action at this time.
0 commit comments