eventize-js
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

eventize.js

npm version Build Status

yet another fantastic event emitter micro framework for javascript!

FEATURES
  • wildcards & priorities
  • has typescript types included 🎉
  • 🚀 powerful api (partial similar to node.js events)
  • all api-calls and downstream-listener-calls are 100% synchronous 💥 no async! 😝
  • supports all major browsers and Node.js environments
  • very small footsprint ~2.8k gzip'd
  • no runtime dependencies
  • apache-2.0 license

Getting Started

Attach the eventizer api to any javascript object you want.

import eventize from 'eventize-js';

const say = hello => world => console.log(hello, world);
const obj = eventize({});

obj.on('foo', say('hello'));

obj.once(['foo', 'bar'], PRIO_A, {
  foo: say('hej'),
});

obj.on(['foo', 'bar'], PRIO_LOW, say('moin moin'))

obj.emit('foo', 'world');
// => "hej world"
// => "hello world"
// => "moin moin world"

obj.on('foo', () => obj.off('foo'));

obj.emit(['foo', 'bar'], 'eventize');
// => "hello eventize"
// => "moin moin eventize"

Installation

Install the latest version with: npm install --save eventize-js

API Reference

The eventize API

eventize()

eventize( obj )  // alias for eventize.inject()

eventize.inject( obj )  // => eventizer === obj
eventize.extend( obj )  // => eventizer (prototype is obj)
eventize.create( obj )  // => eventizer

.. or if you like a more class based approach ..

import {Eventize} from 'eventize-js';

class Foo extends Eventize {
  // foo has now the eventize superpowers!
}

The eventizer API

on()

.on( eventName*, [ priority, ] listenerFunc [, listenerObject] )
.on( eventName*, [ priority, ] listenerFuncName, listenerObject )
.on( eventName*, [ priority, ] listenerObject )

.on( [ priority, ] listenerFunc [, listenerObject] )   => listenerObject.on( '*', listenerFunc )
.on( [ priority, ] listenerObject )                    => listenerObject.on( '*', listenerObject )

eventName*:       eventName | Array<eventName>
eventName:        string

listenerFunc:     function
listenerFuncName: string
listenerObject:   object

once()

eventizer.once( ... )

emit()

eventizer.emit( eventName* [, args... ] )

off()

eventizer.off( listenerFunc [, listenerObject] )
eventizer.off( listenerFuncName, listenerObject )
eventizer.off( listenerObject )
eventizer.off( eventName )
eventizer.off()

retain()

eventizer.retain( eventName* )

Additional API Helpers

eventize.is( obj )

Check if obj is an eventizer (object has the eventizer api implemented). Returns true or false

eventize.PRIO_MAX
eventize.PRIO_A
eventize.PRIO_B
eventize.PRIO_C
eventize.PRIO_DEFAULT = 0
eventize.PRIO_LOW
eventize.PRIO_MIN

Some predefined priorities. Use it or not. They are defined just for convenience.

Readme

Keywords

none

Package Sidebar

Install

npm i eventize-js

Weekly Downloads

1

Version

1.1.1

License

Apache-2.0

Unpacked Size

111 kB

Total Files

35

Last publish

Collaborators

  • spearwolf