From c56a1eb78b76b52cbeeed6fe16d3511c1fd41147 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Feb 2022 09:46:22 -0400 Subject: super basic album ↔ track linking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/thing/cacheable-object.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/thing/cacheable-object.js') diff --git a/src/thing/cacheable-object.js b/src/thing/cacheable-object.js index 3c14101c..9af41603 100644 --- a/src/thing/cacheable-object.js +++ b/src/thing/cacheable-object.js @@ -83,6 +83,8 @@ function inspect(value) { } export default class CacheableObject { + static instance = Symbol('CacheableObject `this` instance'); + #propertyUpdateValues = Object.create(null); #propertyUpdateCacheInvalidators = Object.create(null); @@ -100,6 +102,19 @@ export default class CacheableObject { constructor() { this.#defineProperties(); this.#initializeUpdatingPropertyValues(); + + if (CacheableObject.DEBUG_SLOW_TRACK_INVALID_PROPERTIES) { + return new Proxy(this, { + get: (obj, key) => { + if (!Object.hasOwn(obj, key)) { + if (key !== 'constructor') { + CacheableObject._invalidAccesses.add(`(${obj.constructor.name}).${key}`); + } + } + return obj[key]; + } + }); + } } #initializeUpdatingPropertyValues() { @@ -227,7 +242,8 @@ export default class CacheableObject { const dependencyKeys = expose.dependencies || []; const dependencyGetters = dependencyKeys.map(key => () => [key, this.#propertyUpdateValues[key]]); - const getAllDependencies = () => Object.fromEntries(dependencyGetters.map(f => f())); + const getAllDependencies = () => Object.fromEntries(dependencyGetters.map(f => f()) + .concat([[this.constructor.instance, this]])); if (flags.update) { return () => transform(this.#propertyUpdateValues[property], getAllDependencies()); @@ -268,4 +284,22 @@ export default class CacheableObject { } }; } + + static DEBUG_SLOW_TRACK_INVALID_PROPERTIES = false; + static _invalidAccesses = new Set(); + + static showInvalidAccesses() { + if (!this.DEBUG_SLOW_TRACK_INVALID_PROPERTIES) { + return; + } + + if (!this._invalidAccesses.size) { + return; + } + + console.log(`${this._invalidAccesses.size} unique invalid accesses:`); + for (const line of this._invalidAccesses) { + console.log(` - ${line}`); + } + } } -- cgit 1.3.0-6-gf8a5