@@ -3,11 +3,13 @@ import type { IModelType as MSTIModelType, ModelActions } from "mobx-state-tree"
3
3
import { types as mstTypes } from "mobx-state-tree" ;
4
4
import "reflect-metadata" ;
5
5
import { RegistrationError } from "./errors" ;
6
- import { $fastInstantiator , buildFastInstantiator } from "./fast-instantiator" ;
6
+ import { buildFastInstantiator } from "./fast-instantiator" ;
7
7
import { defaultThrowAction , mstPropsFromQuickProps , propsFromModelPropsDeclaration } from "./model" ;
8
8
import {
9
9
$env ,
10
10
$identifier ,
11
+ $memoizedKeys ,
12
+ $memos ,
11
13
$originalDescriptor ,
12
14
$parent ,
13
15
$quickType ,
@@ -23,8 +25,6 @@ import type {
23
25
IAnyType ,
24
26
IClassModelType ,
25
27
IStateTreeNode ,
26
- InputTypesForModelProps ,
27
- InputsForModel ,
28
28
InstantiateContext ,
29
29
ModelPropertiesDeclaration ,
30
30
ModelViews ,
@@ -59,8 +59,6 @@ const metadataPrefix = "mqt:properties";
59
59
const viewKeyPrefix = `${ metadataPrefix } :view` ;
60
60
const actionKeyPrefix = `${ metadataPrefix } :action` ;
61
61
const volatileKeyPrefix = `${ metadataPrefix } :volatile` ;
62
- const $memos = Symbol . for ( "mqt:class-model-memos" ) ;
63
- const $memoizedKeys = Symbol . for ( "mqt:class-model-memoized-keys" ) ;
64
62
65
63
/**
66
64
* A map of property keys to indicators for how that property should behave on the registered class
@@ -82,40 +80,19 @@ class BaseClassModel {
82
80
return extend ( this , props ) ;
83
81
}
84
82
83
+ /** Properties set in the fast instantiator compiled constructor, included here for type information */
84
+ [ $readOnly ] ! : true ;
85
+ [ $type ] ! : IClassModelType < TypesForModelPropsDeclaration < any > > ;
85
86
/** @hidden */
86
87
readonly [ $env ] ?: any ;
87
88
/** @hidden */
88
89
readonly [ $parent ] ?: IStateTreeNode | null ;
89
90
/** @hidden */
90
- [ $memos ] = null ;
91
+ [ $identifier ] ?: any ;
91
92
/** @hidden */
92
- [ $memoizedKeys ] = null ;
93
+ [ $memos ] ! : Record < string , any > | null ;
93
94
/** @hidden */
94
- [ $identifier ] ?: any ;
95
-
96
- constructor (
97
- snapshot : InputsForModel < InputTypesForModelProps < TypesForModelPropsDeclaration < any > > > | undefined ,
98
- context : InstantiateContext ,
99
- parent : IStateTreeNode | null ,
100
- /** @hidden */ hackyPreventInitialization = false
101
- ) {
102
- if ( hackyPreventInitialization ) {
103
- return ;
104
- }
105
-
106
- this [ $env ] = context . env ;
107
- this [ $parent ] = parent ;
108
-
109
- ( this . constructor as IClassModelType < any > ) [ $fastInstantiator ] ( this as any , snapshot , context ) ;
110
- }
111
-
112
- get [ $readOnly ] ( ) {
113
- return true ;
114
- }
115
-
116
- get [ $type ] ( ) {
117
- return this . constructor as IClassModelType < TypesForModelPropsDeclaration < any > > ;
118
- }
95
+ [ $memoizedKeys ] ! : Record < string , boolean > | null ;
119
96
}
120
97
121
98
/**
@@ -162,7 +139,7 @@ export function register<Instance, Klass extends { new (...args: any[]): Instanc
162
139
tags ?: RegistrationTags < Instance > ,
163
140
name ?: string
164
141
) {
165
- const klass = object as any as IClassModelType < any > ;
142
+ let klass = object as any as IClassModelType < any > ;
166
143
const mstActions : ModelActions = { } ;
167
144
const mstViews : ModelViews = { } ;
168
145
const mstVolatiles : Record < string , VolatileMetadata > = { } ;
@@ -263,6 +240,7 @@ export function register<Instance, Klass extends { new (...args: any[]): Instanc
263
240
}
264
241
case "volatile" : {
265
242
mstVolatiles [ metadata . property ] = metadata ;
243
+ break ;
266
244
}
267
245
}
268
246
}
@@ -310,7 +288,7 @@ export function register<Instance, Klass extends { new (...args: any[]): Instanc
310
288
( klass as any ) . mstType = ( klass as any ) . mstType . volatile ( ( self : any ) => initializeVolatiles ( { } , self , mstVolatiles ) ) ;
311
289
}
312
290
313
- klass [ $fastInstantiator ] = buildFastInstantiator ( klass ) ;
291
+ klass = buildFastInstantiator ( klass ) ;
314
292
( klass as any ) [ $registered ] = true ;
315
293
316
294
return klass as any ;
0 commit comments