1 Star 2 Fork 0

Lib4JavaScript/universal-event-bus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
bluefox update 2a693e8 9个月前
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

js版本事件总线(类似 android EventBus)

使用说明

1、安装

npm install  universal-event-bus

2、在需要的地方注册事件(需要更新用户数据)

事件的注册跟解除注册需要配对使用,否则会导致内存泄漏; (一般在页面开始的时候注册,页面结束的时候解除。具体根据实际情况而定)

 let eventBus = require('universal-event-bus')
 
 //注册()
 eventBus.register(this, false, 'updateUserInfo', (msg)=>{
    //  msg收到的用户消息,执行相关更新操作
 )
 
 //解除注册
 eventBus.unregister(this);
 

3、发送消息

消息分为普通消息跟粘性消息;普通消息只有在发送消息前注册才能收到,粘性消息,在消息发送之后注册,也能收得到; 要接收粘性消息,需要在注册的时候进行标识(即 第二个参数传 true)

  eventBus.post({name:"AAA",age:20},'updateUserInfo')  
  或者
  eventBus.postSticky({name:"AAA",age:20},'updateUserInfo');//发送粘性消息

4、销毁所有的事件

eventBus.destroy();
MIT License Copyright (c) 2021 bluefox Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

js版本的事件总线(参考了Android event-bus 的思想); 主要用于页面之间的数据传递(小程序、h5, pc-web); 也可用于小程序插件页面跟普通页面之间的数据传递; 展开 收起
JavaScript 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/supeijin_JavaScript/universal-event-bus.git
git@gitee.com:supeijin_JavaScript/universal-event-bus.git
supeijin_JavaScript
universal-event-bus
universal-event-bus
master

搜索帮助

371d5123 14472233 46e8bd33 14472233