【Odoo16前端源码分析】xml模板文件编译后的代码

以webclient.xml为例,这是WebClient组件对应的模板文件(WebClient是App启动时实例化的入口组件)

/* odoo/addons/web/static/src/webclient/webclient.xml */

<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

    <t t-name="web.WebClient" owl="1">
        <t t-if="!state.fullscreen">
            <NavBar/>
        </t>
        <ActionContainer/>
        <MainComponentsContainer/>
    </t>

</templates>

编译后的代码

(function anonymous(app, bdom, helpers
) {
  let { text, createBlock, list, multi, html, toggler, comment } = bdom;
  // Template name: "web.WebClient"
  const comp1 = app.createComponent(`NavBar`, true, false, false, true);
  const comp2 = app.createComponent(`ActionContainer`, true, false, false, true);
  const comp3 = app.createComponent(`MainComponentsContainer`, true, false, false, true);
  
  return function template(ctx, node, key = "") {
    let b2,b3,b4;
    if (!ctx['state'].fullscreen) {
      b2 = comp1({}, key + `__1`, node, this, null);
    }
    b3 = comp2({}, key + `__2`, node, this, null);
    b4 = comp3({}, key + `__3`, node, this, null);
    return multi([b2, b3, b4]);
  }
})

编译后的代码是通过new Function方式动态创建的匿名函数,创建组件时执行的是匿名函数返回的闭包template

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值