Skip to content

Latest commit

 

History

History
executable file
·
75 lines (53 loc) · 1.36 KB

README.md

File metadata and controls

executable file
·
75 lines (53 loc) · 1.36 KB

EventEmitter

JS 自定义事件消息通知,类似 jquey 的事件机制。

If I can help you, please give me a star, tahnk you!

Installation

ES Module Import

yarn add @tulies/event-emitter
import EventEmitter from '@tulies/event-emitter'

引入文件

<script src="/dist/event-emitter.umd.js"></script>
<script>
  EventEmitter.on(type, listener)
</script>

Basic Usage

全局调用,全局共享事件监听。

const listener = function (data) {
  console.log(new Date(), 'custom-event 回调中返回:', data)
}
// 添加事件监听
EventEmitter.on('custom-event', listener)

// 取消事件监听
EventEmitter.off('custom-event', listener)

// 事件消息通知
EventEmitter.emit('custom-event', { name: '我是custom-event 的回调数据' })

具体实例调用,每个实例相互独立

var eventEmitter = new EventEmitter()
const listener = function (data) {
  console.log(new Date(), 'custom-event 回调中返回:', data)
}
// 添加事件监听
eventEmitter.on('custom-event', listener)

// 取消事件监听
eventEmitter.off('custom-event', listener)

// 事件消息通知
eventEmitter.emit('custom-event', { name: '我是custom-event 的回调数据' })

Dist / Build

Development Build

$ yarn dev

Production Build

$ yarn build