DeviceEventEmmiter使用

发送广播一个事件

DeviceEventEmitter.emit('updatePlantList', '创建工厂成功');//通知刷新工厂列表

接收处,添加监听(监听要再事件发生之前添加,否则无法回调)

componentDidMount() {
this.fetch(); this.subscription = DeviceEventEmitter.addListener('userNameDidChange', (userName) => { // alert('通知'); this.fetch(); }); }; componentWillUnmount() { this.subscription.remove(); }; componentWillMount() { this.fetch(); };

 个人认为内部首先不是用的本地广播就是一套观察者模式, 有时间了看一下源码,再回来补充文章

posted @ 2020-04-16 14:56  GLORY-HOPE  阅读(209)  评论(0编辑  收藏  举报