-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding multiple listeners at once #15787
Conversation
With a more general function name like this, we may want to consider also adding support for multiple listeners as well. Also supporting the same signature as Type checking will also be needed no matter what. |
Can you be more specific? Do you propose to add one event to multiple handlers beside multiple events to one handler?
So, instead of
No problem, easy peasy. But something strange I noticed is that no type checking is done in |
I meant being able to do any one of: ee.onMultiple(['foo','bar','baz'], handler); ee.onMultiple('foo', [handler1, handler2, handler3]); // To clarify, this example would add each of the 3 handlers to each event passed
ee.onMultiple(['foo','bar','baz'], [handler1, handler2, handler3]); As previously suggested in the original discussion on this, it might also be beneficial to support object variants, like: ee.onMultiple({
foo: handler1,
bar: [handler2, handler3]
});
No, I mean: ee.onMultiple('foo', handler); to avoid users having to do their own checking to know whether they should call
That's because the type checking for |
const emptyFunction = function() {}; | ||
|
||
// Test | ||
await myEE.onMultiple(inputArray, emptyFunction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this awaited? I'm also not sure this actually tests the feature itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this awaited?
Good point. I'll fix it. Thanks.
I'm also not sure this actually tests the feature itself.
To me, it seems like you're not conviced that using .eventNames(
) isn't the proper way to test the code. I mean, I could agree on some degree. How do you propose to change it?
That seems implausible because |
@bnoordhuis Sorry, I misinterpreted that point. One question: if I lint, will the indentation of my code be gone? |
The linter only points out issues, it doesn't auto-fix them. |
@bnoordhuis I tried to execute (cut because too long) |
Do you have spaces ( |
- Accept an object as input parameter now - Change unit tests accordingly
Ok now this syntax is used:
I changed my unit test accordingly (now bad cases are handled yet). No type check is done since it is done in P.S.: My test passes. Now I am running all the test suites |
It seems like all tests passed, but in the end I get this error:
What does it mean? |
@Giovarco Pull in the latest changes from node master and the error should go away. |
@mscdex I moved to local master and pulled from remote and nothing apparently happened. Now I stop here:
Do you think that It could be a good idea to work directly on the stable node 8.6.0 instead of 9.0.0 PRE to avoid this kind of problems? |
@Giovarco from your fork:
|
|
||
const functionArray = obj[event]; | ||
|
||
for(let i = 0; i < functionArray.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should allow for the simple case also:
ee.onMultiple({
event1() { },
event2() { }
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what that object represents. Is it like an array?
await myEE.emit("event2"); | ||
await myEE.emit("event3"); | ||
|
||
assert.deepStrictEqual(ok, 3, "Some handlers were not executed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap the functions in the input with a common.mustCall()
and this check becomes unnecessary.
e.g.
const input = {
event1: [ common.mustCall() ],
event2: [ common.mustCall(), common.mustCall() ]
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did it!
Just noting... this would also need documentation. |
This pull request is all about solve this open issue / feature request: #15697 .
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
events