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

eventr

v0.5.1

Published

A solution to async flow control

Downloads

18

Readme

Eventr

Build Status

实现得太烂, 不推荐使用

install

npm install eventr

quick example

var Eventr = require('eventr');
var et = new Eventr();
et.emit('google', '!!!');
et.emit('bing', '???');
et.on(['google', 'bing'], function (edata) {
  console.log(edata.google); // => !!!
  console.log(edata.bing); // => ???
});

usage

normal usage

et.on(eventName, function (edata) {})

it('should work with one event', function (done) {
  var et = new Eventr();
  et.emit('hello', 'ok');
  // edata is what you emit
  et.on('hello', function (edata) {
    edata.should.equal('ok');
    done();
  });
});

event array

et.on([eventName1, eventName2, ..], function (edata) {}

it('should work with event array', function (done) {
  var et = new Eventr();
  fetchurl('google', function (err, content) {
    et.emit('page1', content);
  });
  fetchurl('yahoo', function (err, content) {
    et.emit('page2', content);
  });
  // edata is a hash
  et.on(['page1', 'page2'], function (edata) {
    edata.page1.should.equal('pagecontentgoogle');
    edata.page2.should.equal('pagecontentyahoo');
    done();
  });
});

chain multi listeners

it('should work in order', function (done) {
  var et = new Eventr();

  fetchurl('file1', function (err, content) {
    et.emit('file1', content);
  });
  fetchurl('file2', function (err, content) {
    et.emit('file2', content);
  });

  et.on(['file1', 'file2'], function (edata) {
    fetchurl('file3', et.done(function (content) {
      edata.file3 = content;
      et.emit('allfile', edata);
    }));
  });

  et.on('allfile', function (edata) {
    // concat file1 and file2 and file3
    var content = edata.file1 + edata.file2 + edata.file3;
    content.should.equal('pagecontentfile1pagecontentfile2pagecontentfile3');
    done();
  });
});

map array to another

  • on(eventName, total, function (dataArr) {})
  • emit(eventName, data, index)
  • done(eventName, index)
it('should ensure `emit` order', function (done) {
  var et = new Eventr();
  et.on('doc', 5, function (docs) {
    docs.should.eql([1, 4, 9, 16, 25]);
    done();
  });

  var datas = [1, 2, 3, 4, 5];
  datas.forEach(function (d, idx) {
    setTimeout(function () {
      et.emit('doc', d * d, idx);
    }, 5 - d);
  });
});

#emit and #emitNow

et.emit('google', 'Im feeling lucky')
et.emitNow('google', 'Im feeling lucky')

when you call et.emit('sth', data), the sth event would trigger in process.nextTick. If you want it emit as soon as possible, call et.emitNow('sth', data).

#done and #err

#done would handle callback err for you.

#done has three forms. each form return a function (err, data).

et.done(eventName) // handle err, and auto `emit(eventName, data)`
et.done(eventName, thenFn) // handle err, and auto `emit(eventName, thenFn(data))`
et.done(callback) // only handle err, you should emit manually. `callback(data)` only receive data.

#err has two form.

et.err(errHandler) // errHandler is a function, et.done would use it.
et.err(err) // err is a JS Error. et use errHandler to handle it
it('should work with event array', function (done) {
  var et = new Eventr();
  et.err(done);
  fetchurl('google', et.done('page1'));
  fetchurl('yahoo', et.done('page2'));
  et.on(['page1', 'page2'], function (edata) {
    edata.page1.should.equal('pagecontentgoogle');
    edata.page2.should.equal('pagecontentyahoo');
    done();
  });
});

TODO

  • [ ] browser UMD support