xte

1.0.2 • Public • Published

xte

介绍

xte是一款事件发布与订阅的库。

xte

xte for event-emitter.

中文文档 | English Doc

安装

npm i --save xte

简单使用

import XTE from 'xte'

XTE.get().on('e1', (e) => {
    console.log('收到事件e1', e);
})

XTE.get().emit('e1', {test: 1, a: "a"});

XTE.get().off('e1');

同个事件使用多个处理器

function h1(e) {
    console.log('处理器1收到事件', e);
}
function h2(e) {
    console.log('处理器2收到事件', e);
}

XTE.get().on('e2', h1);
XTE.get().on('e2', h2);

//发送事件e2,这时h1和h2都能收到
XTE.get().emit('e2', {test: 1, a: "a"});

//关闭事件e2中的h1处理器
XTE.get().off('e2', h1);

//发送事件e2,只有h2能收到
XTE.get().emit('e2', {test: 1, a: "a"});

//关闭事件e2中的h1处理器
XTE.get().off('e2', h2);

//发送事件e2, 都没了
XTE.get().emit('e2', {test: 1, a: "a"});

API

使用简单,接口只有on, emit和off.

  • on(eventName: string, callback: Function): 监听事件.
  • emit(eventName: string, ...parameters: any[]): 发送事件.
  • off(eventName?: string, callback?: Function): 取消事件.

License

木兰宽松许可证@toolset.

Readme

Keywords

none

Package Sidebar

Install

npm i xte

Weekly Downloads

3

Version

1.0.2

License

木兰宽松许可证

Unpacked Size

18.2 kB

Total Files

9

Last publish

Collaborators

  • xiangtao