@tulies/event-middleware
v1.0.0-beta.2
Published
JS自定义事件消息通知,类似jaquey的事件机制。
Downloads
1
Readme
EventMiddleware
JS 自定义事件消息订阅通知,类似 jquey 的事件机制。
If I can help you, please give me a star, tahnk you!
仓库更新为 @tulies/event-emitter,https://github.com/tulies/event-emitter
Installation
ES Module Import
yarn add @tulies/event-middleware
import EventMiddleware from '@tulies/event-middleware'
引入文件
<script src="/dist/event-middleware.umd.js"></script>
<script>
EventMiddleware.on(type, listener)
</script>
Basic Usage
全局调用,全局共享事件监听。
const listener = function (data) {
console.log(new Date(), 'custom-event 回调中返回:', data)
}
// 添加事件监听
EventMiddleware.on('custom-event', listener)
// 取消事件监听
EventMiddleware.off('custom-event', listener)
// 事件消息通知
EventMiddleware.emit('custom-event', { name: '我是custom-event 的回调数据' })
具体实例调用,每个实例相互独立
var eventMiddleware = new EventMiddleware()
const listener = function (data) {
console.log(new Date(), 'custom-event 回调中返回:', data)
}
// 添加事件监听
eventMiddleware.on('custom-event', listener)
// 取消事件监听
eventMiddleware.off('custom-event', listener)
// 事件消息通知
eventMiddleware.emit('custom-event', { name: '我是custom-event 的回调数据' })
Dist / Build
Development Build
$ yarn dev
Production Build
$ yarn build