Javascript 出现故障后,使用mufa停止react组件之间的通信

Javascript 出现故障后,使用mufa停止react组件之间的通信,javascript,reactjs,publish-subscribe,mufa,Javascript,Reactjs,Publish Subscribe,Mufa,我使用sub/pub模式via在React组件之间进行通信,而不是道具。然后,我们将简化父组件中的逻辑(正如您在下面的代码片段中所注意到的) const{on,fire}=mufa; 类输入扩展了React.Component{ onChange(事件){ fire('input_change',event.target.value); } render(){ 返回 } } 类标签扩展了React.Component{ 状态={text::}; componentDidMount(){ on(

我使用sub/pub模式via在React组件之间进行通信,而不是道具。然后,我们将简化父组件中的逻辑(正如您在下面的代码片段中所注意到的)

const{on,fire}=mufa;
类输入扩展了React.Component{
onChange(事件){
fire('input_change',event.target.value);
}
render(){
返回
}
}
类标签扩展了React.Component{
状态={text::};
componentDidMount(){
on('input_change',this.onInputChange.bind(this));
}
onInputChange(inputValue){
this.setState({text:inputValue});
//当inputValue达到10个字符时,我需要代码停止调用此方法。
}
render(){
返回{this.state.text}
}
}
类应用程序扩展了React.Component{
//由于Sub/Pub模式,这里没有逻辑。
render(){
返回(
)
}
}
ReactDOM.render(,document.getElementById('app'))

看起来
mufa
有一种方法可以这样取消订阅:

const mufa=new mufa();
警察,失火,不明嫌犯=mufa;
类输入扩展了React.Component{
onChange(事件){
fire('input_change',event.target.value);
}
render(){
返回
}
}
类标签扩展了React.Component{
状态={text::};
建造师(道具){
超级(道具);
this.sub=null;
}
componentDidMount(){
this.sub=on('input_change',this.onInputChange.bind(this));
}
onInputChange(inputValue){
如果(inputValue.length>=10){
不明嫌犯(本分案);
返回;
};
this.setState({text:inputValue});
//当inputValue达到10个字符时,我需要代码停止调用此方法。
}
render(){
返回{this.state.text}
}
}
类应用程序扩展了React.Component{
//由于Sub/Pub模式,这里没有逻辑。
render(){
返回(
)
}
}
ReactDOM.render(,document.getElementById('app'))

不明嫌犯
关闭
:这两种方法根据