Socket
Socket
Sign inDemoInstall

any-event

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

any-event

小巧的事件模型


Version published
Weekly downloads
1.7K
decreased by-53.07%
Maintainers
1
Weekly downloads
 
Created
Source

any-event NPM Version npm bundle size (minified + gzip) codecov CircleCI

:cake: 不到1k, 一个mini的事件管理器, 希望能在您的代码中做一块砖.

安装

npm i -S any-event

使用

import EventEmitter from  'any-event';
const emitter = new EventEmitter();
emitter.on('add', data=>{
    console.log(data) // 1
});
emitter.emit('add', 1);

方法

on(eventName, listener)

绑定事件

名称类型数据类型是否必填说明
eventName参数String/Symbol事件名称
listener参数Function对应的回调函数
emitter返回值EventEmitter---实例

off(eventName, listener)

解除绑定, 如果不填写listener, 那么eventName对应的listener都会被移除.

名称类型数据类型是否必填说明
eventName参数String/Symbol事件名称
listener参数Function对应的回调函数
emitter返回值EventEmitter---实例
const callback = data=>{
    alert(data)
};
emitter.on('add', callback);
// 解除绑定
emitter.off('add', callback);
// add事件不会触发
emitter.emit('add', 1);

emit(eventName [, ...args])

触发事件, 支持任意数量参数

名称类型数据类型是否必填说明
eventName参数String/Symbol事件名称
args参数Any数据
emitter返回值Boolean---实例
const callback = (a,b,c,d)=>{
    console(a,b,c,d); // 1,2,3,4
};
emitter.once('add', callback);
// add事件触发
emitter.emit('add', 1,2,3,4);

destroy()

销毁实例

const callback = (a,b,c,d)=>{
    console(a,b,c,d); // 1,2,3,4
};
emitter.once('add', callback);
emitter.destroy();

// add事件不会触发
emitter.emit('add', 1,2,3,4);

Keywords

FAQs

Package last updated on 30 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc