Web components vs. React

Web components vs. React - LogRocket Blog

Web Components + Compose 是一条更好的路线。

当然,像 molecule 一样用 HTML 表达继承也是不错的做法,但就像之前构思的一样,需要丰富 HTML 使之图灵完备并支持函数。像下面这样

<template>
  <button m-def="SuperButton">
      <var a="1/number">
      <while "a<100">
          <let a="a+1">
      </while>   
      ${a}
      <if "a % 2 == 0">
         <let this.style.foreColor="red">
      </if>
      <else>
         <let this.style.foreColor="green">
      </else>
  <button>
</template>

上面这段HTML将生成像这样的代码:

class SuperButton extends HMTLButton{
  render(){
    var a = 1;
    while(a<100){
      a = a + 1;
    }
    this.appendText(a);
    if(a % 2 == 0){
      this.style.forColor="red";
    } else {
      this.style.forColor="green";
    }
  }
}
document.registerElement('SuperButton', SuperButton);
posted @ 2023-05-26 11:30  Inshua  阅读(17)  评论(0编辑  收藏  举报