[IMP] component: add name property on nodes for debug purposes

also, improves the implementation of subscriptions
This commit is contained in:
Géry Debongnie
2022-03-11 15:04:12 +01:00
committed by Samuel Degueldre
parent 0625b5883a
commit 47c6d6cc3c
2 changed files with 12 additions and 11 deletions
-4
View File
@@ -117,7 +117,3 @@ Dev mode activates some additional checks and developer amenities:
- [Props validation](./props.md#props-validation) is performed
- [t-foreach](./templates.md#loops) loops check for key unicity
- Lifecycle hooks are wrapped to report their errors in a more developer-friendly way
- Component nodes (the `__owl__` property on components) have an additional "subscriptions"
property, containing a list of objects that the component is observing through the reactivity
system, as well as which keys are observed for each object, which can be useful for
debugging extraneous or missing renders
+12 -7
View File
@@ -58,13 +58,6 @@ export function useState<T extends object>(state: T): Reactive<T> | NonReactive<
batchedRenderFunctions.set(node, render);
// manual implementation of onWillDestroy to break cyclic dependency
node.willDestroy.push(clearReactivesForCallback.bind(null, render));
if (node.app.dev) {
Object.defineProperty(node, "subscriptions", {
get() {
return getSubscriptions(render);
},
});
}
}
return reactive(state, render);
}
@@ -394,4 +387,16 @@ export class ComponentNode<P extends object = any, E = any> implements VNode<Com
}
}
}
// ---------------------------------------------------------------------------
// Some debug helpers
// ---------------------------------------------------------------------------
get name(): string {
return this.component.constructor.name;
}
get subscriptions(): ReturnType<typeof getSubscriptions> {
const render = batchedRenderFunctions.get(this);
return render ? getSubscriptions(render) : [];
}
}