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

object-emitter

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-emitter

EventEmitter with some useful additional functionality.

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
decreased by-36.36%
Maintainers
1
Weekly downloads
 
Created
Source

Overview

Object Emitter adds Event Emitter functionality to an object, creates a new emitter, or can be used to override an existing object's emitter methods. This is similar to the awesome EventEmitter2 module since there is wildcard support.

  • Convenience "mixin" method for easily adding Emitter to any object.
  • All module methods (on, emit, off, etc) are chainable.
  • Wildcard matching enabled by default.
  • Extends existing EventEmitters by working with the _events property.
  • Recognizes Node.js domain usage.
  • Allows default "error" callback to avoid throwing "unspecified 'error' event" error.

Constructor Methods

  • create: Create a new instance of Object Emitter.
  • mixin: Add Object Emitter properties into a target object, never overwriting any existing properties.
  • inject: Force-add Object Emitter properties into the target, overwriting any existing properties if necessary.

Basic Usage

Create new instance of Object Emitter.

var _emitter = require( 'object-emitter' ).create({
  delimiter: ':',
  throwErrors: false
});

_emitter
  .on( '*:two', console.log )
  .emit( 'ping:one', 'I am ignored.' );
  .emit( 'ping:two', 'I am not ignored!' );

Add Object Emitter to a new object.

var MyObject = {};

require( 'object-emitter' ).mixin( MyObject );    

MyObject
  .on( 'ping', console.log )
  .emit( 'ping', 'Chaining works!' );

Extend existing EventEmitter object and utilize wildcards.

require( 'object-emitter' ).mixin( process );    
process.on( '*.ping', console.log );
process.emit( 'ding', 'I am ignored.' );
process.emit( 'ding.ping', 'I am not ignored!' );

The semi "traditional" way of injecting prototypes into new objects works like so:

var ObjectEmitter = require('object-emitter');

function MyConstructor( options ) {

  ObjectEmitter.call(this, {
    delimiter: ':',
    throwErrors: false
  });

  return this;

};

MyConstructor.prototype = Object.create( ObjectEmitter.prototype, {
  constructor: { value: MyConstructor }
});

MyConstructor.prototype.someMethod = function() {}

License

(The MIT License)

Copyright (c) 2013-2014 Usability Dynamics, Inc. info@usabilitydynamics.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 30 Aug 2014

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