Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

emoney

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emoney

A lightweight event emitter for clients and servers

  • 0.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

E$

A lightweight event emitter for clients and servers.

Overview

E$ can be used as a standalone constructor, or to extend prototypical objects.

var emoneyStandalone = E$({
  handleE$: function( e ) { ... }
});

var emoneyExtended = (function() {

  function E$ishConstructor() {
    E$.construct( this );
  }

  E$ishConstructor.prototype = E$.create({
    handleE$: function( e ) { ... }
  });

  return new E$ishConstructor();

}());

E$ provides a clean way to interface with object instances.

emoneyExtended
.$when( 'loading' , function( e , pct ) {
  console.log( 'loading... (' + pct + '%)' );
})
.$when( 'ready' , function( e ) {
  console.log( 'ready!' );
})
.$when( 'error' , function( e , err ) {
  console.error( err.stack );
});

E$ instances can communicate via the handleE$ method.

emoneyExtended.$watch( emoneyStandalone );

// when emoneyStandalone emits an event
emoneyStandalone.$emit( 'gnarly' , [ 'something' , { rad: true }]);

// emoneyExtended.handleE$ is executed with arguments:
// [ event , something , { rad: true }]

Methods

Static Methods

E$.create( prototype )

creates a new object that extends the E$ prototype.

E$ishConstructor.prototype = E$.create({
  method1: function() { ... },
  method2: function() { ... },
  handleE$: function( e ) { ... }
});
E$.construct( instance )

defines required properties for an E$ instance.

function E$ishConstructor() {
  E$.construct( this );
  // ...
}
E$.is( subject )

determines whether subject is E$-ish.

var emoney = E$({ gnarly: true });
var emoneyIsh = new E$ishConstructor();
var somethingElse = new SomethingElse();

emoney instanceof E$;     // true
E$.is( emoney );          // true

emoneyIsh instanceof E$;  // false
E$.is( emoneyIsh );       // true

E$.is( somethingElse );   // false

Public Methods

All public methods can be chained.

.$when( events , [ args ] , [ handler ])

adds an event listener.

ParameterTypeDescriptionRequired
eventsString
Array
The event(s) to be handled.yes
argsVariant
Array
The argument(s) to be bound to the event handler.no
handlerFunction
E$
The event handler.
If E$.is( handler ) == true, the event will be bound to instance.handleE$.
If handler is falsy, the event will be bound to emoney.handleE$.
no
// basic use
emoney.$when( 'gnarly' , function( e ) { ... });

// bind an argument to multiple events
emoney.$when([ 'gnarly' , 'rad' ] , 'arg' , function( e , arg ) { ... });

// bind multiple arguments to the wildcard event
emoney.$when( '*' , [ 'arg1' , 'arg2' ] , function( e , arg1 , arg2 ) { ... });
.$once( events , [ args ] , [ handler ])

adds an event listener that is removed after the first time it is invoked.

ParameterTypeDescriptionRequired
eventsString
Array
The event(s) to be handled.yes
argsVariant
Array
The argument(s) to be bound to the event handler.no
handlerFunction
E$
the event handlerno
// basic use
emoney.$once( 'gnarly' , function( e ) { ... });

// bind an argument to multiple events
emoney.$once([ 'gnarly' , 'rad' ] , 'arg' , function( e , arg ) { ... });

// bind multiple arguments to the wildcard event
emoney.$once( '*' , [ 'arg1' , 'arg2' ] , function( e , arg1 , arg2 ) { ... });
.$emit( events , [ args ] , [ callback ])

emits an event.

ParameterTypeDescriptionRequired
eventsString
Array
the event(s) to be emittedyes
argsVariant
Array
the argument(s) to be passed to the event handlerno
callbackFunctiona function to be executed at the end of the event chain (see event behavior)no
// basic use
emoney.$emit( 'gnarly' , function( e ) { ... });

// pass an argument to multiple event handlers
emoney.$emit([ 'gnarly' , 'rad' ] , 'arg' , function( e ) { ... });

// pass multiple arguments to an event handler
emoney.$emit( 'gnarly' , [ 'arg1' , 'arg2' ] , function( e ) { ... });
.$dispel( events , [ wildcard ] , [ handler ])

removes an event listener.

ParameterTypeDescriptionRequired
eventsString
Array
null
The event(s) to be removed.yes
wildcardBooleanA boolean value denoting whether handlers bound to the wildcard event should be removed.no
handlerFunction
E$
the event handlerno
// remove any gnarly listeners bound to handlerFunc
emoney.$dispel( 'gnarly' , handlerFunc );

// remove all gnarly or rad listeners bound to any handler
emoney.$dispel([ 'gnarly' , 'rad' ]);

// remove all listeners bound to handlerFunc except wildcard listeners
emoney.$dispel( null , handlerFunc );

// remove all listeners bound to handlerFunc
emoney.$dispel( null , true , handlerFunc );

// remove all listeners
emoney.$dispel( null , true );
.$watch( emitters )

starts listening to an E$ instance. emitter events will be handled by listener.handleE$.

ParameterTypeDescriptionRequired
emittersE$
Array
The target E$ instance(s).yes
// watch a single emitter
listener.$watch( emitter1 );

// watch multiple emitters
listener.$watch([ emitter1 , emitter2 ]);
.$ignore( emitters )

stops listening to an E$ instance.

ParameterTypeDescriptionRequired
emittersE$
Array
The target E$ instance(s).yes
// ignore a single emitter
listener.$ignore( emitter1 );

// ignore multiple emitters
listener.$ignore([ emitter1 , emitter2 ]);

Events

Properties

PropertyTypeDefaultDescription
targetObjectn/aThe event target.
typeStringn/aThe event type.
defaultPreventedBooleanfalseA flag denoting whether default was prevented.
cancelBubbleBooleanfalseA flag denoting whether propagation was stopped.
timeStampFloatn/aThe time at which the event was first triggered.

Methods

.preventDefault()

prevents the $emit callback from being executed.

emoney
.$when( 'gnarly' , function( e ) {
  e.preventDefault();
  console.log( 'handler1' );
})
.$when( 'gnarly' , function( e ) {
  console.log( 'handler2' );
})
.$emit( 'gnarly' , function( e ) {
  console.log( 'callback' );
});

/*
**  > 'handler1'
**  > 'handler2'
*/
.stopPropagation()

stops execution of the event chain and executes the emit callback.

emoney
.$when( 'gnarly' , function( e ) {
  e.stopPropagation();
  console.log( 'handler1' );
})
.$when( 'gnarly' , function( e ) {
  console.log( 'handler2' );
})
.$emit( 'gnarly' , function( e ) {
  console.log( 'callback' );
});

/*
**  > 'handler1'
**  > 'callback'
*/

Behavior

normal execution

defaultPrevented

cancelBubble

Build & Test

Build configs can be found in Gruntfile.js

default

Builds dev and prod releases, then runs tests.

grunt

test

Builds dev release and then runs tests.

grunt test

debug

Builds dev release, runs tests, then watches source files for changes.

grunt debug

Keywords

FAQs

Package last updated on 10 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc