[IMP] component, reactivity: add subscription getter in dev mode

This allows to see which objects and which keys in those objects a
component is observing, so that issues with missing renders or extra
renders can be more easily diagnosed.
This commit is contained in:
Samuel Degueldre
2022-03-03 09:55:05 +01:00
committed by Géry Debongnie
parent 6908102a72
commit 8920b4b93a
2 changed files with 26 additions and 1 deletions
+11
View File
@@ -153,6 +153,17 @@ export function clearReactivesForCallback(callback: Callback): void {
targetsToClear.clear();
}
export function getSubscriptions(callback: Callback) {
const targets = callbacksToTargets.get(callback) || [];
return [...targets].map((target) => {
const keysToCallbacks = targetToKeysToCallbacks.get(target);
return {
target,
keys: keysToCallbacks ? [...keysToCallbacks.keys()] : [],
};
});
}
const reactiveCache = new WeakMap<Target, WeakMap<Callback, Reactive>>();
/**
* Creates a reactive proxy for an object. Reading data on the reactive object