npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-events-emitter

v1.0.0

Published

javascript 订阅事件和发布事件类

Downloads

2

Readme

简介

javascript 订阅事件和发布事件类

  • 相对于 EventEmitter 这个库可以传 this,改变回调 this 指向

起步

npm i js-events-emitter -S

使用

const JsEventsEmitter= require('js-events-emitter')
// 或
import JsEventsEmitter from 'js-events-emitter'

const events = new JsEventsEmitter()

let _this = new Object()

events.on('custom-event', _this, callbackFunc, ['附加参数1', '附加参数2'])

events.emit('custom-event', ['附加参数3', '附加参数4'])

function callbackFunc(param1, param2, param3, param4) {
  console.log(param1, param2, param3, param4) //'附加参数1', '附加参数2','附加参数3', '附加参数4'
  console.log(this) // this === _this
}

JsEventsEmitter

  • 详情: 订阅事件和发布事件

方法

on

  • 详情: 订阅事件

| 参数 | 类型 | 默认值 | 描述 | | --- | --- | --- | --- | | type | string | | 事件名 | | scope | * | | 作用域 | | callback | function | | 回调 | | [params] | array | [] | 回调参数 |


once

  • 详情: 订阅事件-回调只执行一次

| 参数 | 类型 | 默认值 | 描述 | | --- | --- | --- | --- | | type | string | | 事件名 | | scope | * | | 作用域 | | callback | function | | 回调 | | [params] | array | [] | 回调参数 |


emit

  • 详情: 发布事件

| 参数 | 类型 | 默认值 | 描述 | | --- | --- | --- | --- | | type | string | | | | [params] | array | [] | 附加到回调的参数 |


getListener

  • 详情: 获取指定事件的监听器数组列表

| 参数 | 类型 | 默认值 | 描述 | | --- | --- | --- | --- | | type | string | | 事件名 |

  • 返回:array|undefined- 返回列表

getListenerList

  • 详情: 获取全部事件的全部监听者的列表

  • 返回:object


getEventNames

  • 详情: 获取已经监听的事件名列表

  • 返回:array- 事件名数组


addListener

  • 详情: 添加到事件等待处理触发列表

| 参数 | 类型 | 默认值 | 描述 | | --- | --- | --- | --- | | type | string | | | | [listenerParams] | object | { callback: null, scope: this, params: null, isOnce: false } | 触发事件的参数 |


offAll

  • 详情: 清除所有订阅

| 参数 | 类型 | 默认值 | 描述 | | --- | --- | --- | --- | | type | string,null | | 事件名, 如果指定事件则移除该事件的所有监听器,如果不传则移除所有事件的所有监听器,并注销事件 |


off

  • 详情: 清除对应的订阅

| 参数 | 类型 | 默认值 | 描述 | | --- | --- | --- | --- | | type | string | | 事件名 | | removeCallback | function | | 监听器的回调函数 |