sciter一些简单的查漏补缺
编辑时间:2021-11-02 作者:金满斗 浏览量:406 来源:原创

组件间的全局通讯。好像作者推崇这个

class ComponentA extends Element {
  notifyOthers() {
    Window.post( new Event("app-wide-event") );
  }
  ["on click at button"]() {
    this.notifyOthers();
  }
  render() {
    return <div.a>
      <h2>ComponentA</h2>
      <button>Fire app wide event</button>
    </div>;
  }
}

另一边

class ComponentB extends Element {
  counter = 0; // number of received events
  componentDidMount() {
    const callback = () =>
      this.componentUpdate {
        counter: this.counter + 1
      };

    this.onGlobalEvent("app-wide-event", callback );
  }
  render() {
    return <div.b>
      <h2>ComponentB</h2>
      Received {this.counter} events 
    </div>;
  }
}

传统的添加事件方式

Window.this.on("statechange", function() {
   
});

document.on("click","button#info", function(){

});


来说两句吧