组件间的全局通讯。好像作者推崇这个
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(){
});