Skip to content

Commit 69c46b0

Browse files
committed
Add isCached API to detect @cached decorator usage
- Add computed.isCached() API to detect properties using @cached decorator - Update EMBER_INSPECTOR_API_ANALYSIS.md with isCached documentation - Implement stub in ember-inspector-api.js with heuristic detection - @cached is from @glimmer/tracking and memoizes getter results This provides a public API to identify cached properties without relying on internal implementation details.
1 parent b29c19b commit 69c46b0

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

EMBER_INSPECTOR_API_ANALYSIS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ interface EmberInspectorAPI {
306306
* @returns true if this is a mandatory setter
307307
*/
308308
isMandatorySetter: (descriptor: any) => boolean;
309+
310+
/**
311+
* Check if a property uses the @cached decorator from @glimmer/tracking.
312+
* The @cached decorator memoizes getter results and invalidates when dependencies change.
313+
*
314+
* @param obj - The object
315+
* @param key - The property name
316+
* @returns true if the property uses @cached decorator
317+
*/
318+
isCached: (obj: object, key: string) => boolean;
309319
};
310320

311321
// Render tree debugging

ember_debug/utils/ember-inspector-api.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,45 @@ export const emberInspectorAPI = {
351351
.call(descriptor.set)
352352
.includes('You attempted to update');
353353
},
354+
355+
/**
356+
* Check if a property uses the @cached decorator from @glimmer/tracking.
357+
* The @cached decorator memoizes getter results and invalidates when dependencies change.
358+
*
359+
* @param {Object} obj - The object
360+
* @param {string} key - The property name
361+
* @returns {boolean} True if the property uses @cached decorator
362+
*/
363+
isCached(obj, key) {
364+
// STUB: Would be implemented by ember-source
365+
// For now, try to detect @cached by checking for specific patterns
366+
// In production, ember-source would provide this as a public API
367+
368+
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
369+
if (!descriptor?.get) {
370+
return false;
371+
}
372+
373+
// @cached creates a native getter with a special tag
374+
// Ember would know internally if a property is cached
375+
// For now, we can check if it has a getter and is tracked
376+
// but not a computed property (computed properties have _getter)
377+
const isComputed = require('./type-check').isComputed;
378+
if (isComputed(obj, key)) {
379+
return false;
380+
}
381+
382+
// Check if the getter has tracking metadata
383+
// This is a heuristic - ember-source would have definitive knowledge
384+
try {
385+
const { tagForProperty } = require('../utils/ember');
386+
const tag = tagForProperty(obj, key);
387+
// If it has a tag but isn't computed, it's likely @cached or @tracked
388+
return !!tag;
389+
} catch {
390+
return false;
391+
}
392+
},
354393
},
355394

356395
// Render tree debugging

0 commit comments

Comments
 (0)