Socket
Socket
Sign inDemoInstall

addon-emitter

Package Overview
Dependencies
13
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    addon-emitter

event emitter class for native addons


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Install size
9.09 MB
Created
Weekly downloads
 

Readme

Source

addon-emitter

event emitter class for native addons.

usage

using a native addon (here foo) with event emitter:

var Foo = require('foo')
var foo = new Foo()

foo.on('sus', function (a, b) {
  console.log('Received:', a, b);
})

the Foo class inherits the public interface of the Emitter class:

// foo.h

#include <nan.h>
#include <emitter.h>

// inherit from the Emitter class
class Foo : public Emitter {
public:
  static void Init(v8::Local<v8::Object> exports);

private:
  explicit Foo ();
  ~Foo ();

  void Bar ();
};

set the method for the event listening (usually the on method):

// foo.cc

void Foo::Init(v8::Local<v8::Object> exports) {
  v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);

  // setting the prototype method for the event listening
  Nan::SetPrototypeMethod(tpl, "on", Emitter::On);
}

to emit an event from Foo:

void Foo::Bar(const Nan::FunctionCallbackInfo<v8::Value>& info) {
  // the first parameter is the name of the event,
  // after that you can write as many parameters as needed,
  // but they have to convertible to v8's `Local<Value>` type
  Emit(Nan::New("sus").ToLocalChecked()
      , Nan::New("a string").ToLocalChecked(), 123);
}

the example above is just to show what you have to do to use the module. it's not a fully functioning program. for a working example check the test folder.

install

npm i addon-emitter

in binding.gyp:

{
  'include_dirs': [ "<!(node -e \"require('addon-emitter')\")" ]
}

Keywords

FAQs

Last updated on 25 Aug 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc