@tulies/event-middleware
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-beta.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @tulies/event-middleware

Weekly Downloads

0

Version

1.0.0-beta.2

License

ISC

Unpacked Size

33.2 kB

Total Files

12

Last publish

Collaborators

  • tulies