1
- import type { Tag } from " @glimmer/interfaces" ;
1
+ import type { Tag } from ' @glimmer/interfaces' ;
2
2
3
- import type { MonomorphicTagImpl } from " ./validators" ;
3
+ import type { MonomorphicTagImpl } from ' ./validators' ;
4
4
5
- import { infoForTag , tagFor } from " ./meta" ;
6
- import { track } from " ./tracking" ;
7
- import { validateTag , valueForTag } from " ./validators" ;
5
+ import { infoForTag , tagFor } from ' ./meta' ;
6
+ import { track } from ' ./tracking' ;
7
+ import { validateTag , valueForTag } from ' ./validators' ;
8
8
9
9
type Info = {
10
10
tag : MonomorphicTagImpl ;
11
11
latestValue : number ;
12
12
dependencies : {
13
- object : object ,
13
+ object : object ;
14
14
propertyKey : string ;
15
15
changed : boolean ;
16
16
} [ ] ;
17
- }
17
+ } ;
18
18
19
19
export function getTrackedDependencies ( obj : Record < string , any > , property : string , info ?: Info ) {
20
- info = info || { } as Info ;
20
+ info = info || ( { } as Info ) ;
21
21
const tag = info ?. tag || track ( ( ) => obj [ property ] ) ;
22
22
const dependencies = [ ] ;
23
23
// do not include tracked properties from dependencies
@@ -36,11 +36,12 @@ export function getTrackedDependencies(obj: Record<string, any>, property: strin
36
36
let maxRevision = info ?. latestValue || valueForTag ( tag ) ;
37
37
let minRevision = Infinity ;
38
38
dependencies . forEach ( ( t ) => {
39
- maxRevision = Math . max ( maxRevision , valueForTag ( t . tag ) ) ;
40
- minRevision = Math . min ( minRevision , valueForTag ( t . tag ) ) ;
39
+ const value = valueForTag ( t . tag ) ;
40
+ maxRevision = Math . max ( maxRevision , value ) ;
41
+ minRevision = Math . min ( minRevision , value ) ;
41
42
} ) ;
42
43
43
- const hasChange = info . latestValue && ( maxRevision !== info . latestValue ) || false ;
44
+ const hasChange = ( info . latestValue && maxRevision !== info . latestValue ) || false ;
44
45
let latestValue = valueForTag ( tag ) ;
45
46
46
47
info . latestValue = latestValue ;
@@ -61,19 +62,19 @@ type TrackedInfo = {
61
62
} ;
62
63
63
64
export function getChangedProperties ( obj : object , trackedInfo ?: TrackedInfo ) {
64
- trackedInfo = trackedInfo || { } as TrackedInfo ;
65
+ trackedInfo = trackedInfo || ( { } as TrackedInfo ) ;
65
66
trackedInfo [ 'changed' ] = [ ] ;
66
67
trackedInfo . propertyInfo = trackedInfo . propertyInfo || { } ;
67
68
for ( const name in obj ) {
68
69
let tagInfo = trackedInfo . propertyInfo ?. [ name ] || {
69
70
tag : tagFor ( obj , name ) ,
70
- revision : ( tagFor ( obj , name ) as MonomorphicTagImpl ) [ 'revision' ] ,
71
+ revision : ( tagFor ( obj , name ) as MonomorphicTagImpl ) [ 'revision' ] ,
71
72
} ;
72
73
if ( ! tagInfo . tag ) return ;
73
74
trackedInfo . propertyInfo [ name ] = tagInfo ;
74
75
75
76
const changed = ! validateTag ( tagInfo . tag , tagInfo . revision ) ;
76
- tagInfo . revision = ( tagInfo . tag as MonomorphicTagImpl ) [ " revision" ]
77
+ tagInfo . revision = ( tagInfo . tag as MonomorphicTagImpl ) [ ' revision' ] ;
77
78
if ( changed ) {
78
79
trackedInfo [ 'changed' ] . push ( name ) ;
79
80
}
0 commit comments