New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

nsevent

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nsevent

> 有命名空间的事件监听器 - event emitter with namespace

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

nsevent

有命名空间的事件监听器 - event emitter with namespace

on(eventName, fn, namespace)

参数必选说明
eventName监听事件名
fn回调函数
namespace命名空间
NSEvent.on('add', (a, b) => {
  console.log(a, b);
});

NSEvent.on('add', (a, b) => {
  console.log(a, b, 'ns');
}, 'ns');

// 1, 2
// 1, 2, 'ns'
NSEvent.emit('add', a, b);  

once(eventName, fn)

参数必选说明
eventName监听事件名
fn回调函数
NSEvent.once('add', (a, b) => {
  console.log(a, b);
});

NSEvent.emit('add', 1, 2);      // 1, 2
NSEvent.emit('add', 1, 2);      // nothing

emit(eventName, arg1, arg2, ..., object)

参数必选说明
eventName监听事件名
arg[1,2,3...]传递给回调函数的值
object{ 最后一个传递对象,ns: ['ns'] } 可以指定命名空间触发事件
NSEvent.on('fire', () => {
  console.log('fire ns');
}, 'ns');

NSEvent.on('fire', () => {
  console.log('fire ns2');
}, 'ns');

NSEvent.on('fire', () => {
  console.log('fire');
});

NSEvent.emit('fire');     // fire ns, fire ns2, fire
console.log("======");
NSEvent.emit('fire', 1, 2, { ns: [] });     // nothing
NSEvent.emit('fire', 1, 2, { ns: ['ns'] }); // fire ns, fire ns2

off(eventName, [string|function|array])

参数必选说明
eventName监听事件名
stringfunctionarray
string指定命名空间解绑
function指定函数解绑
array通过数组指定命名空间或者函数解绑
const NSEvent = require('../dist/nsevent.cjs');

NSEvent.on('fire', () => {
  console.log('fire ns');
}, 'ns');

NSEvent.on('fire', () => {
  console.log('fire ns');
}, 'ns');

NSEvent.on('fire', () => {
  console.log('fire1');
}, 'ns1');

NSEvent.emit('fire');   // fire ns, fire ns, fire1
console.log('==========');
NSEvent.off('fire', ['ns']);
NSEvent.emit('fire');   // fire1
console.log('==========');
NSEvent.off('fire', 'ns1');
NSEvent.emit('fire');   // none

FAQs

Package last updated on 22 Nov 2018

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