Skip to content

Commit 8df6767

Browse files
committedFeb 12, 2024
fix
1 parent 0f0c535 commit 8df6767

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed
 

‎packages/@glimmer/validator/lib/tracked-utils.ts

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import type { Tag } from "@glimmer/interfaces";
1+
import type { Tag } from '@glimmer/interfaces';
22

3-
import type { MonomorphicTagImpl } from "./validators";
3+
import type { MonomorphicTagImpl } from './validators';
44

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';
88

99
type Info = {
1010
tag: MonomorphicTagImpl;
1111
latestValue: number;
1212
dependencies: {
13-
object: object,
13+
object: object;
1414
propertyKey: string;
1515
changed: boolean;
1616
}[];
17-
}
17+
};
1818

1919
export function getTrackedDependencies(obj: Record<string, any>, property: string, info?: Info) {
20-
info = info || {} as Info;
20+
info = info || ({} as Info);
2121
const tag = info?.tag || track(() => obj[property]);
2222
const dependencies = [];
2323
// do not include tracked properties from dependencies
@@ -36,11 +36,12 @@ export function getTrackedDependencies(obj: Record<string, any>, property: strin
3636
let maxRevision = info?.latestValue || valueForTag(tag);
3737
let minRevision = Infinity;
3838
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);
4142
});
4243

43-
const hasChange = info.latestValue && (maxRevision !== info.latestValue) || false;
44+
const hasChange = (info.latestValue && maxRevision !== info.latestValue) || false;
4445
let latestValue = valueForTag(tag);
4546

4647
info.latestValue = latestValue;
@@ -61,19 +62,19 @@ type TrackedInfo = {
6162
};
6263

6364
export function getChangedProperties(obj: object, trackedInfo?: TrackedInfo) {
64-
trackedInfo = trackedInfo || {} as TrackedInfo;
65+
trackedInfo = trackedInfo || ({} as TrackedInfo);
6566
trackedInfo['changed'] = [];
6667
trackedInfo.propertyInfo = trackedInfo.propertyInfo || {};
6768
for (const name in obj) {
6869
let tagInfo = trackedInfo.propertyInfo?.[name] || {
6970
tag: tagFor(obj, name),
70-
revision: (tagFor(obj, name) as MonomorphicTagImpl)['revision'],
71+
revision: (tagFor(obj, name) as MonomorphicTagImpl)['revision'],
7172
};
7273
if (!tagInfo.tag) return;
7374
trackedInfo.propertyInfo[name] = tagInfo;
7475

7576
const changed = !validateTag(tagInfo.tag, tagInfo.revision);
76-
tagInfo.revision = (tagInfo.tag as MonomorphicTagImpl)["revision"]
77+
tagInfo.revision = (tagInfo.tag as MonomorphicTagImpl)['revision'];
7778
if (changed) {
7879
trackedInfo['changed'].push(name);
7980
}

‎packages/@glimmer/validator/test/meta-test.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
dirtyTagFor,
3-
infoForTag,
4-
tagFor,
5-
validateTag,
6-
valueForTag,
7-
} from '@glimmer/validator';
1+
import { dirtyTagFor, infoForTag, tagFor, validateTag, valueForTag } from '@glimmer/validator';
82

93
import { module, test } from './-utils';
104

‎packages/@glimmer/validator/test/tracked-utils-test.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import {
2-
getChangedProperties, getTrackedDependencies, trackedData
3-
} from '@glimmer/validator';
1+
import { getChangedProperties, getTrackedDependencies, trackedData } from '@glimmer/validator';
42

53
import { module, test } from './-utils';
64

75
module('@glimmer/validator: tracked-utils', () => {
8-
96
class TestObject {
107
declare item1: string;
118
declare item2: string;
@@ -70,7 +67,7 @@ module('@glimmer/validator: tracked-utils', () => {
7067
changed: false,
7168
object: obj,
7269
propertyKey: 'item2',
73-
}
70+
},
7471
]);
7572

7673
obj.item1 = 'hi';
@@ -84,7 +81,7 @@ module('@glimmer/validator: tracked-utils', () => {
8481
changed: false,
8582
object: obj,
8683
propertyKey: 'item2',
87-
}
84+
},
8885
]);
8986
assert.deepEqual(getTrackedDependencies(obj, 'getterWithTracked', info).dependencies, [
9087
{
@@ -96,7 +93,7 @@ module('@glimmer/validator: tracked-utils', () => {
9693
changed: false,
9794
object: obj,
9895
propertyKey: 'item2',
99-
}
96+
},
10097
]);
10198
});
10299
});

0 commit comments

Comments
 (0)