@@ -21,7 +21,7 @@ export const DEBUG_MERGED_CELLS = new Set<MergedCell>();
21
21
export const DEBUG_CELLS = new Set < Cell > ( ) ;
22
22
var currentTracker : Set < Cell > | null = null ;
23
23
let _isRendering = false ;
24
- const cellsMap = new WeakMap < object , Record < string , Cell < unknown > > > ( ) ;
24
+ export const cellsMap = new WeakMap < object , Map < string | number | symbol , Cell < unknown > > > ( ) ;
25
25
26
26
export function getCells ( ) {
27
27
return Array . from ( DEBUG_CELLS ) ;
@@ -40,9 +40,9 @@ if (IS_DEV_MODE) {
40
40
}
41
41
}
42
42
43
- function keysFor ( obj : object ) : Record < string , Cell < unknown > > {
43
+ function keysFor ( obj : object ) : Map < string | number | symbol , Cell < unknown > > {
44
44
if ( ! cellsMap . has ( obj ) ) {
45
- cellsMap . set ( obj , { } ) ;
45
+ cellsMap . set ( obj , new Map ( ) ) ;
46
46
}
47
47
return cellsMap . get ( obj ) ! ;
48
48
}
@@ -56,26 +56,26 @@ export function tracked(
56
56
return {
57
57
get ( ) {
58
58
const keys = keysFor ( this ) ;
59
- if ( ! ( key in keys ) ) {
59
+ if ( ! keys . has ( key ) ) {
60
60
const value : any = cell (
61
61
hasInitializer
62
62
? descriptor ! . initializer ?. call ( this )
63
63
: descriptor ?. value ,
64
64
`${ klass . constructor . name } .${ key } .@tracked` ,
65
65
) ;
66
- keys [ key ] = value ;
66
+ keys . set ( key , value ) ;
67
67
return value . value ;
68
68
} else {
69
- return keys [ key ] . value ;
69
+ return keys . get ( key ) ! . value ;
70
70
}
71
71
} ,
72
72
set ( newValue : any ) {
73
73
const keys = keysFor ( this ) ;
74
- if ( ! ( key in keys ) ) {
75
- keys [ key ] = cell ( newValue , `${ klass . constructor . name } .${ key } .@tracked` ) ;
74
+ if ( ! keys . has ( key ) ) {
75
+ keys . set ( key , cell ( newValue , `${ klass . constructor . name } .${ key } .@tracked` ) ) ;
76
76
return ;
77
77
}
78
- const _cell = keys [ key ] ;
78
+ const _cell = keys . get ( key ) ! ;
79
79
if ( _cell . value === newValue ) {
80
80
return ;
81
81
}
@@ -278,15 +278,15 @@ export function cellFor<T extends object, K extends keyof T>(
278
278
obj : T ,
279
279
key : K ,
280
280
) : Cell < T [ K ] > {
281
- const refs = cellsMap . get ( obj ) || { } ;
282
- if ( key in refs ) {
283
- return refs [ key as unknown as string ] as Cell < T [ K ] > ;
281
+ const refs = cellsMap . get ( obj ) || new Map < string | number | symbol , Cell > ( ) ;
282
+ if ( refs . has ( key ) ) {
283
+ return refs . get ( key ) as Cell < T [ K ] > ;
284
284
}
285
285
const cellValue = new Cell < T [ K ] > (
286
286
obj [ key ] ,
287
287
`${ obj . constructor . name } .${ String ( key ) } ` ,
288
288
) ;
289
- refs [ key as unknown as string ] = cellValue ;
289
+ refs . set ( key , cellValue ) ;
290
290
cellsMap . set ( obj , refs ) ;
291
291
Object . defineProperty ( obj , key , {
292
292
get ( ) {
@@ -326,3 +326,7 @@ export function inNewTrackingFrame(callback: () => void) {
326
326
callback ( ) ;
327
327
currentTracker = existingTracker ;
328
328
}
329
+
330
+ export function getTracker ( ) {
331
+ return currentTracker ;
332
+ }
0 commit comments