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

act.js

v2.0.1

Published

Compact Event Emitter for browser (and server), with all necessary features.

Downloads

13

Readme

Act

:zap: Compact event emitter for browser (and server), with all necessary features. If you need tiny and not overloaded event system, you are in the right place. :checkered_flag: :wink:

  • Compact -> Tiny size (~500 bytes)
  • Full -> All Node's EventEmitter capabilities
  • Universal -> Browser and server compatible
  • Support -> IE 9+

How to Install

Install, using NPM:

$ npm install act.js --save

Include

As Node.js/Webpack/Browserify module:

// ES6 modules
import Act from 'act.js'

// CommonJS modules
const Act = require('act.js')

In browser:

<script src="https://unpkg.com/act.js/dist/act.min.js"></script>

How to Use

Just call it:

const act = Act()

Or use with class/objects (composition):

const myObject = {
    myFunction: function() {},
    emitter: Act()
}

API methods

After you have created event emitter object, this methods become available:

Properties

events

Returns a copy of the events object.

act.events // { eventName: [ [Function], [Function] ] }

Methods

on(event, handler, prepend)

Add handler to event or all events, executed when this event(events) is fired. The third argument says that the handler must be prepended to the handlers array.

act.on('data', () => {})

// add handler to the beginning of the array
act.on('data', () => {}, true)

// subscribe handler for all events
act.on('*', () => {})

once(event, handler, prepend)

Add handler to event, which can be called only once. You can also use * event type and prepend argument in once method.

act.once('data', () => {})

off(event[,handler])

Remove handler from event, event or all events.

// Handler for 'message' event
const show = () => {}
act.on('data', show)

// remove handler
act.off('data', show) 

// remove event with all handlers
act.off('data') 

// remove all events
act.off() 

fire(event[,arguments])

Emit event with arguments.

act.fire('data', 34, 'Jason')

Example

import Act from 'act.js'

const act = Act();

act.on('data', (data) => console.log('Next:', ++data.num))
act.on('notification', (name, msg) => console.log(name, ':', msg));
act.once('*', () => console.log('Called for all events.'));

console.log(act.events);

act.fire('data', { num: 11 });
act.fire('notification', 'Jason', 'Hello!');

// Otput:
// $ { data: [ [Function] ], notification: [ [Function] ], '*': [ { [Function] _once: true } ] }
// $ Next: 12
// $ Called for all events.
// $ Jason : Hello!

Compliance with the Node`s EE

emitter.on(eventName, listener) -> act.on(eventName, listener)
emitter.emit(eventName, args) -> act.fire(eventName, args)
emitter.eventNames() -> Object.keys(act.events)
emitter.listenerCount(eventName) -> act.events[eventName].length
emitter.listeners(eventName) -> act.events[eventName]
emitter.once(eventName, listener) -> act.once(eventName, listener)
emitter.prependListener(eventName, listener) -> act.on(eventName, listener, true)
emitter.prependOnceListener(eventName, listener) -> act.once(eventName, listener, true)
emitter.removeAllListeners() -> act.off()
emitter.removeAllListeners(eventName) -> act.off(eventName) // Removes event listeners.
emitter.removeListener(eventName, listener) -> act.off(eventName, listener)

forthebadge

License

MIT. © 2017 Taras Batenkov