1.0.2 • Published 4 years ago

xte v1.0.2

Weekly downloads
-
License
木兰宽松许可证
Repository
-
Last release
4 years ago

xte

Introduce

xte is an event publish and subscribe library。

xte

xte for event-emitter.

中文文档 | English Doc

Install

npm i --save xte

Use

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');

Use multiple processors for the same event

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

The interface is only on, emit and off

  • on(eventName: string, callback: Function): subscribe events.
  • emit(eventName: string, ...parameters: any[]): publish event.
  • off(eventName?: string, callback?: Function): Cancel event.

License

MulanPSL2@toolset.

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago