mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[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:
committed by
Aaron Bohy
parent
df2d6b6a0e
commit
c03042b44d
@@ -261,8 +261,7 @@ export class QWebCompiler {
|
||||
return block;
|
||||
}
|
||||
|
||||
insertBlock(expression: string, block: BlockDescription, ctx: Context): string | null {
|
||||
let id: string | null = null;
|
||||
insertBlock(expression: string, block: BlockDescription, ctx: Context): void {
|
||||
let blockExpr = block.generateExpr(expression);
|
||||
const tKeyExpr = ctx.tKeyExpr;
|
||||
if (block.parentVar) {
|
||||
@@ -271,7 +270,7 @@ export class QWebCompiler {
|
||||
keyArg = `${tKeyExpr} + ${keyArg}`;
|
||||
}
|
||||
this.addLine(`${block.parentVar}[${ctx.index}] = withKey(${blockExpr}, ${keyArg});`);
|
||||
return id;
|
||||
return;
|
||||
}
|
||||
|
||||
if (tKeyExpr) {
|
||||
@@ -283,7 +282,6 @@ export class QWebCompiler {
|
||||
} else {
|
||||
this.addLine(`let ${block.varName} = ${blockExpr};`);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
generateCode(): string {
|
||||
|
||||
+2
-5
@@ -302,11 +302,8 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
||||
if (tagName === "pre") {
|
||||
ctx = { inPreTag: true };
|
||||
}
|
||||
let ref = null;
|
||||
if (node.hasAttribute("t-ref")) {
|
||||
ref = node.getAttribute("t-ref");
|
||||
node.removeAttribute("t-ref");
|
||||
}
|
||||
const ref = node.getAttribute("t-ref");
|
||||
node.removeAttribute("t-ref");
|
||||
|
||||
for (let child of node.childNodes) {
|
||||
const ast = parseNode(child, ctx);
|
||||
|
||||
+3
-21
@@ -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;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user