@@ -27,7 +27,7 @@ import {
27
27
} from "mobx-state-tree" ;
28
28
import type { FlowReturn } from "mobx-state-tree/dist/internal" ;
29
29
import { CantRunActionError } from "./errors" ;
30
- import { $context , $parent , $quickType , $readOnly , $type , $identifier } from "./symbols" ;
30
+ import { $context , $parent , $quickType , $readOnly , $type } from "./symbols" ;
31
31
import type {
32
32
CreateTypes ,
33
33
IAnyComplexType ,
@@ -236,57 +236,7 @@ export function resolveIdentifier<T extends IAnyModelType>(
236
236
if ( ! context ) {
237
237
throw new Error ( "can't resolve references in a readonly tree with no context" ) ;
238
238
}
239
- const cache = ( context as any ) . referenceCache ;
240
- if ( cache && typeof cache . get === "function" ) {
241
- return cache . get ( identifier ) as Instance < T > | undefined ;
242
- }
243
- const root : any = getRoot < IAnyType > ( target ) ;
244
- const visited = new Set < any > ( ) ;
245
- const isTargetType = ( node : any ) : boolean => {
246
- try {
247
- return ( isType ( type ) ? type : ( type as any ) ) . is ( node ) ;
248
- } catch {
249
- return false ;
250
- }
251
- } ;
252
- const stack : any [ ] = [ root ] ;
253
- while ( stack . length ) {
254
- const node = stack . pop ( ) ;
255
- if ( ! node || typeof node !== "object" || visited . has ( node ) ) continue ;
256
- visited . add ( node ) ;
257
- if ( $readOnly in node ) {
258
- const id = node [ $identifier ] ;
259
- if ( id === identifier && isTargetType ( node ) ) {
260
- return node as Instance < T > ;
261
- }
262
- for ( const key of Object . keys ( node ) ) {
263
- const val = node [ key ] ;
264
- if ( val && typeof val === "object" ) {
265
- stack . push ( val ) ;
266
- }
267
- }
268
- if ( Array . isArray ( node ) ) {
269
- for ( const val of node ) stack . push ( val ) ;
270
- }
271
- if ( node instanceof Map ) {
272
- for ( const val of node . values ( ) ) stack . push ( val ) ;
273
- }
274
- } else {
275
- for ( const key of Object . keys ( node ) ) {
276
- const val = node [ key ] ;
277
- if ( val && typeof val === "object" ) {
278
- stack . push ( val ) ;
279
- }
280
- }
281
- if ( Array . isArray ( node ) ) {
282
- for ( const val of node ) stack . push ( val ) ;
283
- }
284
- if ( node instanceof Map ) {
285
- for ( const val of node . values ( ) ) stack . push ( val ) ;
286
- }
287
- }
288
- }
289
- return undefined as Instance < T > | undefined ;
239
+ return context . referenceCache . get ( identifier ) as Instance < T > | undefined ;
290
240
}
291
241
292
242
export const applySnapshot = < T extends IAnyType > ( target : IStateTreeNode < T > , snapshot : SnapshotIn < T > ) : void => {
0 commit comments