@@ -3,11 +3,13 @@ import type { IModelType as MSTIModelType, ModelActions } from "mobx-state-tree"
33import { types as mstTypes } from "mobx-state-tree" ;
44import "reflect-metadata" ;
55import { RegistrationError } from "./errors" ;
6- import { $fastInstantiator , buildFastInstantiator } from "./fast-instantiator" ;
6+ import { buildFastInstantiator } from "./fast-instantiator" ;
77import { defaultThrowAction , mstPropsFromQuickProps , propsFromModelPropsDeclaration } from "./model" ;
88import {
99 $env ,
1010 $identifier ,
11+ $memoizedKeys ,
12+ $memos ,
1113 $originalDescriptor ,
1214 $parent ,
1315 $quickType ,
@@ -23,8 +25,6 @@ import type {
2325 IAnyType ,
2426 IClassModelType ,
2527 IStateTreeNode ,
26- InputTypesForModelProps ,
27- InputsForModel ,
2828 InstantiateContext ,
2929 ModelPropertiesDeclaration ,
3030 ModelViews ,
@@ -59,8 +59,6 @@ const metadataPrefix = "mqt:properties";
5959const viewKeyPrefix = `${ metadataPrefix } :view` ;
6060const actionKeyPrefix = `${ metadataPrefix } :action` ;
6161const volatileKeyPrefix = `${ metadataPrefix } :volatile` ;
62- const $memos = Symbol . for ( "mqt:class-model-memos" ) ;
63- const $memoizedKeys = Symbol . for ( "mqt:class-model-memoized-keys" ) ;
6462
6563/**
6664 * A map of property keys to indicators for how that property should behave on the registered class
@@ -82,40 +80,19 @@ class BaseClassModel {
8280 return extend ( this , props ) ;
8381 }
8482
83+ /** Properties set in the fast instantiator compiled constructor, included here for type information */
84+ [ $readOnly ] ! : true ;
85+ [ $type ] ! : IClassModelType < TypesForModelPropsDeclaration < any > > ;
8586 /** @hidden */
8687 readonly [ $env ] ?: any ;
8788 /** @hidden */
8889 readonly [ $parent ] ?: IStateTreeNode | null ;
8990 /** @hidden */
90- [ $memos ] = null ;
91+ [ $identifier ] ?: any ;
9192 /** @hidden */
92- [ $memoizedKeys ] = null ;
93+ [ $memos ] ! : Record < string , any > | null ;
9394 /** @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 ;
11996}
12097
12198/**
@@ -162,7 +139,7 @@ export function register<Instance, Klass extends { new (...args: any[]): Instanc
162139 tags ?: RegistrationTags < Instance > ,
163140 name ?: string
164141) {
165- const klass = object as any as IClassModelType < any > ;
142+ let klass = object as any as IClassModelType < any > ;
166143 const mstActions : ModelActions = { } ;
167144 const mstViews : ModelViews = { } ;
168145 const mstVolatiles : Record < string , VolatileMetadata > = { } ;
@@ -263,6 +240,7 @@ export function register<Instance, Klass extends { new (...args: any[]): Instanc
263240 }
264241 case "volatile" : {
265242 mstVolatiles [ metadata . property ] = metadata ;
243+ break ;
266244 }
267245 }
268246 }
@@ -310,7 +288,7 @@ export function register<Instance, Klass extends { new (...args: any[]): Instanc
310288 ( klass as any ) . mstType = ( klass as any ) . mstType . volatile ( ( self : any ) => initializeVolatiles ( { } , self , mstVolatiles ) ) ;
311289 }
312290
313- klass [ $fastInstantiator ] = buildFastInstantiator ( klass ) ;
291+ klass = buildFastInstantiator ( klass ) ;
314292 ( klass as any ) [ $registered ] = true ;
315293
316294 return klass as any ;
0 commit comments