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

pee

v0.0.11

Published

Pass event emitter

Downloads

16

Readme

Pee - Pass Event Emitter

Event emitter with some fancy shortcut.

  • Emit events delayed.
  • Route events.

Examples

Coffee-script example.

    {PassEventEmitter} = require 'PassEventEmitter'

    ee1 = new PassEventEmitter()
    ee1.on 'event', (e) -> console.log 'ee1', e
    ee2 = new PassEventEmitter()
    ee2.on 'event', (e) -> console.log 'ee2', e

    ee2.pass 'event', ee1

    ee1.emit 'event', 'data'

    ###
    Output is:
    ee1 data
    ee2 data
    ###

Javascript example.

    PassEventEmitter = require('PassEventEmitter').PassEventEmitter;

    ee1 = new PassEventEmitter();
    ee1.on('event', function (e) { console.log('ee1', e); });
    ee2 = new PassEventEmitter();
    ee2.on('event', function (e) { console.log('ee2', e); });

    ee2.pass('event', ee1);

    ee1.emit('event', 'data');

    /*
    Output is:
    ee1 data
    ee2 data
    */

API

PassEventEmitter is inherited form EventEmitter class so all of its functions are usable.

.emitLater(event, data, timeout)

.emitLater(event, data, timeout)

Emits the event delayed.

using pee | by hand --------- | ------- source.emitLater 'event', data, 100 | do (data) -> setTimeout (source.emit 'event', data), 100

.emitEvery(event, data, timeout)

.emitEvery(event, data, timeout)

Emits the event every timeout ms.

using pee | by hand --------- | ------- source.emitEvery 'event', data, 100 | do (data) -> setInterval (source.emit 'event', data), 100

.pass(events, targets)

.pass(events, targets)

Registers a delegate which emits the received event to target.

using pee | by hand --------- | ------- source.pass 'event', target | source.on 'event', (e) -> target.emit e source.pass 'e1 e2', target | source.on 'e1', (e) -> target.emit e source.on 'e2', (e) -> target.emit e source.pass 'e1 e2', t1, t2 or source.pass 'e1 e2', [t1, t2] | source.on 'e1', (e) -> t1.emit e source.on 'e2', (e) -> t1.emit e source.on 'e1', (e) -> t2.emit e source.on 'e2', (e) -> t2.emit e source.pass 'e1': t1, 'e2': t2 | source.on 'e1', (e) -> t1.emit e source.on 'e2', (e) -> t2.emit e

static PassEventEmitter.getGlobal()

PassEventEmitter.getGlobal() # Static call

Returns a global PassEventEmitter instance.

static PassEventEmitter.pass(class, events, targets)

PassEventEmitter.pass(class, events, targets) # Static call

If class is given, then it registers a route for a delegate which emits the received event to target. The route is created when an instance of class is created.

Note: If class is not given it passes the event to the global emitter. Same as PassEventEmitter.getGlobal().pass('e', pee).

using pee

class ClassA extends PassEventEmitter
target = new PassEventEmitter()
target.on 'event', (e) -> console.log 'target.event', e

PassEventEmitter.pass ClassA, 'event', target

new ClassA().emit 'event', 'a1'
new ClassA().emit 'event', 'a2'
new ClassA().emit 'event', 'a3'

PassEventEmitter.removeAllRoutes() # to avoid leak

###
Outputs
target.event a1
target.event a2
target.event a3
###

by hand

class ClassA extends EventEmitter
target = new EventEmitter()
target.on 'event', (e) -> console.log 'target.event', e

pass = (e) -> target.emit 'event', e

a1 = new ClassA()
a1.on 'event', pass
a1.emit 'event', 'a1'
a2 = new ClassA()
a2.on 'event', pass
a2.emit 'event', 'a2'
a3 = new ClassA()
a3.on 'event', pass
a3.emit 'event', 'a3'

###
Outputs
target.event a1
target.event a2
target.event a3
###

License

MIT

dist/PassEventEmitter.browser.min.js is generated with browserify, that uses a package with also an MIT license.