diff --git a/.npmignore b/.npmignore index 5c51d45..0046f11 100644 --- a/.npmignore +++ b/.npmignore @@ -1,11 +1,14 @@ -.idea +*.log .cproject -.project -.lock-wscript .DS_Store +.eslintrc +.gitignore +.idea +.lock-wscript +.project +CPPLINT.cfg Debug +examples node_modules package-lock.json -*.log -.gitignore test diff --git a/CPPLINT.cfg b/CPPLINT.cfg new file mode 100644 index 0000000..cb3f171 --- /dev/null +++ b/CPPLINT.cfg @@ -0,0 +1,13 @@ +set noparent +linelength=110 +filter=-legal/copyright +filter=-build/include_order +filter=-build/header_guard +filter=-build/namespaces +filter=-build/include_what_you_use +filter=-whitespace/blank_line +filter=-whitespace/comments +filter=-whitespace/tab +filter=-whitespace/end_of_line +filter=-whitespace/indent +filter=-readability/todo diff --git a/include/event-emitter.hpp b/include/event-emitter.hpp index 1e7ba42..0f5d39a 100644 --- a/include/event-emitter.hpp +++ b/include/event-emitter.hpp @@ -57,16 +57,19 @@ public: // -------- dynamic Nan::SetPrototypeMethod(proto, "listenerCount", jsListenerCount); + Nan::SetPrototypeMethod(proto, "addEventListener", jsAddListener); Nan::SetPrototypeMethod(proto, "addListener", jsAddListener); + Nan::SetPrototypeMethod(proto, "dispatchEvent", jsDispatchEvent); Nan::SetPrototypeMethod(proto, "emit", jsEmit); Nan::SetPrototypeMethod(proto, "eventNames", jsEventNames); Nan::SetPrototypeMethod(proto, "getMaxListeners", jsGetMaxListeners); Nan::SetPrototypeMethod(proto, "listeners", jsListeners); - Nan::SetPrototypeMethod(proto, "on", jsOn); - Nan::SetPrototypeMethod(proto, "once", jsOnce); + Nan::SetPrototypeMethod(proto, "on", jsAddListener); + Nan::SetPrototypeMethod(proto, "once", jsAddListener); Nan::SetPrototypeMethod(proto, "prependListener", jsPrependListener); Nan::SetPrototypeMethod(proto, "prependOnceListener", jsPrependOnceListener); Nan::SetPrototypeMethod(proto, "removeAllListeners", jsRemoveAllListeners); + Nan::SetPrototypeMethod(proto, "removeEventListener", jsRemoveListener); Nan::SetPrototypeMethod(proto, "removeListener", jsRemoveListener); Nan::SetPrototypeMethod(proto, "setMaxListeners", jsSetMaxListeners); Nan::SetPrototypeMethod(proto, "rawListeners", jsRawListeners); @@ -199,6 +202,23 @@ private: static NAN_METHOD(jsAddListener) { _wrapListener(info); } + static NAN_METHOD(jsDispatchEvent) { THIS_EVENT_EMITTER; + + REQ_OBJ_ARG(0, event); + + if (!event->Has(JS_STR("type"))) { + return Nan::ThrowError("Event must have the `type` property."); + } + + Nan::Utf8String name(event->Get(JS_STR("type"))); + + V8_VAR_VAL args = event; + + eventEmitter->emit(*name, 1, &args); + + } + + static NAN_METHOD(jsEmit) { THIS_EVENT_EMITTER; REQ_UTF8_ARG(0, name); @@ -416,8 +436,6 @@ private: } - static NAN_METHOD(jsOn) { _wrapListener(info); } - static NAN_METHOD(jsOnce) { _wrapOnceListener(info); } static NAN_METHOD(jsPrependListener) { _wrapListener(info, true); } diff --git a/package.json b/package.json index be02adb..256c062 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "addon-tools-raub", - "version": "0.1.5", + "version": "0.1.6", "author": "Luis Blanco ", "description": "A set of extra tools for Node.js addons", "main": "index.js",