🎨 Refactor EventEmitter, need stdout debug
This commit is contained in:
parent
08635b0993
commit
e244be7bea
|
@ -10,4 +10,6 @@ filter=-whitespace/comments
|
||||||
filter=-whitespace/tab
|
filter=-whitespace/tab
|
||||||
filter=-whitespace/end_of_line
|
filter=-whitespace/end_of_line
|
||||||
filter=-whitespace/indent
|
filter=-whitespace/indent
|
||||||
|
filter=-whitespace/operators
|
||||||
|
filter=-whitespace/parens
|
||||||
filter=-readability/todo
|
filter=-readability/todo
|
||||||
|
|
|
@ -10,4 +10,6 @@ filter=-whitespace/comments
|
||||||
filter=-whitespace/tab
|
filter=-whitespace/tab
|
||||||
filter=-whitespace/end_of_line
|
filter=-whitespace/end_of_line
|
||||||
filter=-whitespace/indent
|
filter=-whitespace/indent
|
||||||
|
filter=-whitespace/operators
|
||||||
|
filter=-whitespace/parens
|
||||||
filter=-readability/todo
|
filter=-readability/todo
|
||||||
|
|
|
@ -312,7 +312,7 @@ private:
|
||||||
static inline void _addListener(
|
static inline void _addListener(
|
||||||
const Nan::FunctionCallbackInfo<v8::Value> &info,
|
const Nan::FunctionCallbackInfo<v8::Value> &info,
|
||||||
const std::string &name,
|
const std::string &name,
|
||||||
V8_STORE_FUNC &cb,
|
V8_STORE_FUNC *cb,
|
||||||
bool isFront
|
bool isFront
|
||||||
) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
||||||
|
|
||||||
|
@ -320,11 +320,11 @@ private:
|
||||||
eventEmitter->emit("newListener", 2, args);
|
eventEmitter->emit("newListener", 2, args);
|
||||||
|
|
||||||
if (isFront) {
|
if (isFront) {
|
||||||
eventEmitter->_listeners[name].push_front(cb);
|
eventEmitter->_listeners[name].push_front(*cb);
|
||||||
eventEmitter->_raw[name].push_front(cb);
|
eventEmitter->_raw[name].push_front(*cb);
|
||||||
} else {
|
} else {
|
||||||
eventEmitter->_listeners[name].push_back(cb);
|
eventEmitter->_listeners[name].push_back(*cb);
|
||||||
eventEmitter->_raw[name].push_back(cb);
|
eventEmitter->_raw[name].push_back(*cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = eventEmitter->_raw[name].size();
|
int count = eventEmitter->_raw[name].size();
|
||||||
|
@ -361,7 +361,7 @@ private:
|
||||||
V8_STORE_FUNC persistentCb;
|
V8_STORE_FUNC persistentCb;
|
||||||
persistentCb.Reset(cb);
|
persistentCb.Reset(cb);
|
||||||
|
|
||||||
_addListener(info, *name, persistentCb, isFront);
|
_addListener(info, *name, &persistentCb, isFront);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,8 +369,8 @@ private:
|
||||||
static inline void _addOnceListener(
|
static inline void _addOnceListener(
|
||||||
const Nan::FunctionCallbackInfo<v8::Value> &info,
|
const Nan::FunctionCallbackInfo<v8::Value> &info,
|
||||||
const std::string &name,
|
const std::string &name,
|
||||||
V8_STORE_FUNC &raw,
|
V8_STORE_FUNC *raw,
|
||||||
V8_STORE_FUNC &cb,
|
V8_STORE_FUNC *cb,
|
||||||
bool isFront
|
bool isFront
|
||||||
) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
||||||
|
|
||||||
|
@ -378,16 +378,16 @@ private:
|
||||||
eventEmitter->emit("newListener", 2, args);
|
eventEmitter->emit("newListener", 2, args);
|
||||||
|
|
||||||
if (isFront) {
|
if (isFront) {
|
||||||
eventEmitter->_listeners[name].push_front(cb);
|
eventEmitter->_listeners[name].push_front(*cb);
|
||||||
eventEmitter->_raw[name].push_front(raw);
|
eventEmitter->_raw[name].push_front(*raw);
|
||||||
} else {
|
} else {
|
||||||
eventEmitter->_listeners[name].push_back(cb);
|
eventEmitter->_listeners[name].push_back(*cb);
|
||||||
eventEmitter->_raw[name].push_back(raw);
|
eventEmitter->_raw[name].push_back(*raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
int nextId = eventEmitter->_freeId++;
|
int nextId = eventEmitter->_freeId++;
|
||||||
eventEmitter->_wrappedIds[nextId] = cb;
|
eventEmitter->_wrappedIds[nextId] = *cb;
|
||||||
eventEmitter->_rawIds[nextId] = raw;
|
eventEmitter->_rawIds[nextId] = *raw;
|
||||||
|
|
||||||
int count = eventEmitter->_raw[name].size();
|
int count = eventEmitter->_raw[name].size();
|
||||||
|
|
||||||
|
@ -420,12 +420,12 @@ private:
|
||||||
REQ_UTF8_ARG(0, name);
|
REQ_UTF8_ARG(0, name);
|
||||||
REQ_FUN_ARG(1, raw);
|
REQ_FUN_ARG(1, raw);
|
||||||
|
|
||||||
V8_VAR_STR code = JS_STR(
|
V8_VAR_STR code = JS_STR(R"(
|
||||||
"((emitter, name, cb) => (...args) => {\n\
|
((emitter, name, cb) => (...args) => {
|
||||||
cb(...args);\n\
|
cb(...args);
|
||||||
emitter.removeListener(name, cb);\n\
|
emitter.removeListener(name, cb);
|
||||||
})"
|
})
|
||||||
);
|
)");
|
||||||
|
|
||||||
V8_VAR_FUNC decor = V8_VAR_FUNC::Cast(v8::Script::Compile(code)->Run());
|
V8_VAR_FUNC decor = V8_VAR_FUNC::Cast(v8::Script::Compile(code)->Run());
|
||||||
Nan::Callback decorCb(decor);
|
Nan::Callback decorCb(decor);
|
||||||
|
@ -440,7 +440,7 @@ private:
|
||||||
V8_STORE_FUNC persistentRaw;
|
V8_STORE_FUNC persistentRaw;
|
||||||
persistentRaw.Reset(raw);
|
persistentRaw.Reset(raw);
|
||||||
|
|
||||||
_addOnceListener(info, *name, persistentRaw, persistentWrap, isFront);
|
_addOnceListener(info, *name, &persistentRaw, &persistentWrap, isFront);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue