Skip to content

Commit ea7c146

Browse files
authored
add 🔸 to tracked dependencies that caused the last invalidation (#2546)
1 parent 7e837ab commit ea7c146

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

ember_debug/object-inspector.js

+24-18
Original file line numberDiff line numberDiff line change
@@ -217,27 +217,22 @@ function getTagTrackedProps(tag, ownTag, level = 0) {
217217
}
218218
const subtags = tag.subtags || (Array.isArray(tag.subtag) ? tag.subtag : []);
219219
if (tag.subtag && !Array.isArray(tag.subtag)) {
220-
if (tag.subtag._propertyKey)
221-
props.push(
222-
(tag.subtag._object ? getObjectName(tag.subtag._object) + '.' : '') +
223-
tag.subtag._propertyKey
224-
);
220+
if (tag.subtag._propertyKey) props.push(tag.subtag);
221+
225222
props.push(...getTagTrackedProps(tag.subtag, ownTag, level + 1));
226223
}
227224
if (subtags) {
228225
subtags.forEach((t) => {
229226
if (t === ownTag) return;
230-
if (t._propertyKey)
231-
props.push(
232-
(t._object ? getObjectName(t._object) + '.' : '') + t._propertyKey
233-
);
227+
if (t._propertyKey) props.push(t);
234228
props.push(...getTagTrackedProps(t, ownTag, level + 1));
235229
});
236230
}
237231
return props;
238232
}
239233

240-
function getTrackedDependencies(object, property, tag) {
234+
function getTrackedDependencies(object, property, tagInfo) {
235+
const tag = tagInfo.tag;
241236
const proto = Object.getPrototypeOf(object);
242237
if (!proto) return [];
243238
const cpDesc = emberMeta(object).peekDescriptors(property);
@@ -249,21 +244,32 @@ function getTrackedDependencies(object, property, tag) {
249244
const ownTag = tagForProperty(object, property);
250245
const props = getTagTrackedProps(tag, ownTag);
251246
const mapping = {};
252-
props.forEach((p) => {
247+
let maxRevision = tagInfo.revision ?? 0;
248+
let minRevision = Infinity;
249+
props.forEach((t) => {
250+
const p =
251+
(t._object ? getObjectName(t._object) + '.' : '') + t._propertyKey;
253252
const [objName, ...props] = p.split('.');
254253
mapping[objName] = mapping[objName] || new Set();
255-
props.forEach((p) => mapping[objName].add(p));
254+
maxRevision = Math.max(maxRevision, t.revision);
255+
minRevision = Math.min(minRevision, t.revision);
256+
props.forEach((p) => mapping[objName].add([p, t.revision]));
256257
});
257258

259+
const hasChange = maxRevision !== minRevision;
260+
258261
Object.entries(mapping).forEach(([objName, props]) => {
259262
if (props.size > 1) {
260263
dependentKeys.push(objName);
261264
props.forEach((p) => {
262-
dependentKeys.push(' • -- ' + p);
265+
const changed = hasChange && p[1] >= maxRevision ? ' 🔸' : '';
266+
dependentKeys.push(' • -- ' + p[0] + changed);
263267
});
264268
}
265269
if (props.size === 1) {
266-
dependentKeys.push(objName + '.' + [...props][0]);
270+
const p = [...props][0];
271+
const changed = hasChange && p[1] >= maxRevision ? ' 🔸' : '';
272+
dependentKeys.push(objName + '.' + p[0] + changed);
267273
}
268274
if (props.size === 0) {
269275
dependentKeys.push(objName);
@@ -325,7 +331,6 @@ export default class extends DebugPort {
325331
tagInfo.tag = track(() => {
326332
value = object.get?.(item.name) || object[item.name];
327333
});
328-
tagInfo.revision = tagValue(tagInfo.tag);
329334
}
330335
tracked[item.name] = tagInfo;
331336
} else {
@@ -344,8 +349,9 @@ export default class extends DebugPort {
344349
dependentKeys = getTrackedDependencies(
345350
object,
346351
item.name,
347-
tracked[item.name].tag
352+
tracked[item.name]
348353
);
354+
tracked[item.name].revision = tagValue(tracked[item.name].tag);
349355
}
350356
this.sendMessage('updateProperty', {
351357
objectId,
@@ -1121,12 +1127,12 @@ function calculateCPs(
11211127
item.isTracked = true;
11221128
}
11231129
}
1124-
tagInfo.revision = tagValue(tagInfo.tag);
11251130
item.dependentKeys = getTrackedDependencies(
11261131
object,
11271132
item.name,
1128-
tagInfo.tag
1133+
tagInfo
11291134
);
1135+
tagInfo.revision = tagValue(tagInfo.tag);
11301136
} else {
11311137
value = calculateCP(object, item, errorsForObject);
11321138
}

tests/ember_debug/object-inspector-test.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ module('Ember Debug - Object Inspector', function (hooks) {
278278
assert.strictEqual(prop.name, 'getterWithTracked');
279279
assert.strictEqual(prop.value.type, 'type-string');
280280
assert.strictEqual(prop.value.inspect, '"item1item2tracked"');
281-
const dependentKeys =
281+
let dependentKeys =
282282
compareVersion(VERSION, '3.16.10') === 0
283283
? 'item1,item2,trackedProperty'
284284
: 'ObjectWithTracked, • -- item1, • -- item2,Object:My Object.trackedProperty';
@@ -292,6 +292,22 @@ module('Ember Debug - Object Inspector', function (hooks) {
292292
assert.strictEqual(prop.name, 'aCP');
293293
assert.strictEqual(prop.value.type, 'type-boolean');
294294
assert.strictEqual(prop.dependentKeys.toString(), '');
295+
296+
inspected.objectWithTracked.item1 = 'item1-changed';
297+
message = await captureMessage('objectInspector:updateObject', () => {
298+
objectInspector.sendObject(inspected);
299+
});
300+
301+
secondDetail = message.details[1];
302+
prop = secondDetail.properties[1];
303+
assert.strictEqual(prop.name, 'getterWithTracked');
304+
assert.strictEqual(prop.value.type, 'type-string');
305+
assert.strictEqual(prop.value.inspect, '"item1-changeditem2tracked"');
306+
dependentKeys =
307+
compareVersion(VERSION, '3.16.10') === 0
308+
? 'item1,item2,trackedProperty'
309+
: 'ObjectWithTracked, • -- item1 🔸, • -- item2,Object:My Object.trackedProperty';
310+
assert.strictEqual(prop.dependentKeys.toString(), dependentKeys);
295311
});
296312

297313
skip('Correct mixin order with es6 class', async function (assert) {

0 commit comments

Comments
 (0)