简体   繁体   English

永久性dom-if的聚合物预计算

[英]Polymer pre-computation for a permanent dom-if

Is there a way to pre-compute a polymer element based on a condition ? 有没有一种方法可以根据条件预先计算聚合物元素? Let's say for every button, there is an admin button that opens a popup that has debug features. 假设每个按钮都有一个管理按钮,可打开一个具有调试功能的弹出窗口。 As the user will not dynamically become an admin, I'd like to pre-compile my polymer element to avoid the overhead of computing whether it should be displayed every time I insert a button. 由于用户不会动态地成为管理员,因此我想预编译我的聚合物元素,以避免计算每次插入按钮时是否应显示该聚合物元素的开销。

It would probably look like 它可能看起来像

<dom-module id="a-very-common-button">
  <template>
    <div>
      <!-- Remove the button before it is inserted everywhere -->
      <button keep-if="window.isAdmin">
        button for admins
      </button>
      <button>regular button</button>
    </div>
  </template>
</dom-module>

Is it possible ? 可能吗 ?

Just to make sure you understand the implications - you realise that this is all in the client, putting admin content in there would be a severe security issue as anyone could set window.isAdmin=true. 只是为了确保您了解其中的含义-您意识到这一切都在客户端中,将admin内容放入其中将存在严重的安全问题,因为任何人都可以设置window.isAdmin = true。

Apart from that you could extend the native button element providing this function for every standard button. 除此之外,您可以扩展本机按钮元素,为每个标准按钮提供此功能。 https://www.polymer-project.org/1.0/docs/devguide/registering-elements#type-extension https://www.polymer-project.org/1.0/docs/devguide/registering-elements#type-extension

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM