[IMP] qweb/components: remove t-ref on components

Refs to component expose a lot of implementation details that should be
private to parents. Parent to child communication should go through
props.
This commit is contained in:
Samuel Degueldre
2021-11-10 08:18:25 +01:00
committed by Aaron Bohy
parent df2d6b6a0e
commit c03042b44d
8 changed files with 73 additions and 142 deletions
+3 -21
View File
@@ -2,35 +2,17 @@
// useRef
// -----------------------------------------------------------------------------
import type { Component } from "./component/component";
import { getCurrent } from "./component/component_node";
/**
* The purpose of this hook is to allow components to get a reference to a sub
* html node or component.
*/
interface Ref<C extends Component = Component> {
el: HTMLElement | null;
comp: C | null;
}
export function useRef<C extends Component = Component>(name: string): Ref<C> {
export function useRef<T extends HTMLElement = HTMLElement>(name: string): { el: T | null } {
const node = getCurrent()!;
return {
get el(): HTMLElement | null {
const val = node.refs[name];
return val || null;
// if (val instanceof HTMLElement) {
// return val;
// } else if (val instanceof Component) {
// return val.el;
// }
// return null;
},
get comp(): C | null {
return null;
// const val = node.refs && node.refs[name];
// return val instanceof Component ? (val as C) : null;
get el(): T | null {
return node.refs[name] || null;
},
};
}