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

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

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




    
        
            
        
        
        
    

编译后的代码

(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

你可能感兴趣的:(xml,前端,java)