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

eventhandle.js

v1.1.0

Published

an implementation of events based nodeJs, refs eventproxy.js

Downloads

2

Readme

M-eventHandle.js

nodeJs events 拓展事件处理机制, refs eventproxy.js, 自用~

Install

npm install eventhandle.js

继承events

继承events所有方法。events API

新增方法

调用eventHandle

var eventHandle = require("eventhandle.js");
var handle = new eventHandle();

all(eventname1, eventname2..., callback)

all方法会注册所有指定事件,并且在所有事件触发完成之后获取回调。

  • @param eventname1,eventname2... 事件标识
  • @param callback 回调函数
handle.all("aa","bb","cc", function(aa, bb, cc){
  // 在所有事件触发后,将会被调用执行
  // 可以依照顺序获取传入的 aa,bb,cc 的值
});

var aa = "get aa!";
var bb = "get bb!";
var cc = "get cc!";

setTimeout(function(){
// 触发aa,bb,cc 事件	
	handle.emit("aa",aa);
	handle.emit("bb",bb);
	handle.emit("cc",cc);
}, 500);

after(eventname, times, callback)

after方法实现在多次触发统一事件时,在指定触发次数之后获取回调。

  • @param eventname 事件标识
  • @param times 事件被触发次数
  • @param callback 回调
handle.after("after", 3,function(aa, bb, cc){
  // 监听after事件,并在事件触发3次之后会被调用执行
  // 并获取相对应的参数
});

var aa = "get aa!";
var bb = "get bb!";
var cc = "get cc!";

// 此处emit方法在eventname之后传入两个参数,详细参考events API
setTimeout(function(){
	handle.emit("after","aa",aa);
}, 1000);

setTimeout(function(){
	handle.emit("after","bb",bb);
}, 1100);

setTimeout(function(){
	handle.emit("after","cc",cc);
}, 1200);

fail(callback)

fail方法是个异常处理机制,通过监听所有error事件来处理异常情况。

  • @param callback 回调
handle.fail(function(err){
 // 监听error事件,并且获取捕获到的err
 // 此处console.log(err.message) 会显示aa is not defined
});

try{
	aa++;
}catch(err){
	handle.emit("error", err);
}

Test

在终端输入

npm test

Issues

click here