| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
Looks good mostly! :)
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
Last iteration lgtm :]
Thanks for following up on #27977 hope to see you around again 🙏
Sorry, something went wrong.
|
@benjamingr @addaleax Thanks! |
Sorry, something went wrong.
|
@JeniaBR You might find core-validate-commit to be of help with that. |
Sorry, something went wrong.
|
Travis pass 👍 |
Sorry, something went wrong.
|
I think this needs a rebase, as it shows 361 commits. |
Sorry, something went wrong.
There was a problem hiding this comment.
I'm not sure this is the right approach. I would prefer this not to extend EventEmitter.
Also, you can make it a top level helper.
Sorry, something went wrong.
There was a problem hiding this comment.
@mcollina I thought about implementing partial EventTarget and use it for testing.
Something like that EventTarget Example (Also, need to implement in that example above once functionality).
This approach seems to be a little bit exaggerated.
WDYT I should do here?
(If we decide to keep it like that, I will extract it to a top level helper)
Sorry, something went wrong.
There was a problem hiding this comment.
I'm -1 to have the EventTarget example extend EventEmitter. We do not need a full EventTarget implementation, but we could just mock/place assertions on the methods that are used by once.
Sorry, something went wrong.
There was a problem hiding this comment.
done.
Sorry, something went wrong.
There was a problem hiding this comment.
I would prefer this to be on the positive side instead. "if is EventTarget, then ...".
Sorry, something went wrong.
There was a problem hiding this comment.
done.
Sorry, something went wrong.
@mcollina How can I do it properly? I synchronized my master with upstream/master, then I tried to rebase my master with this branch and I get a lot of merge conflicts. |
Sorry, something went wrong.
There was a problem hiding this comment.
Unless I'm missing something, an example showing the use of the EventTarget API would be helpful.
Sorry, something went wrong.
There was a problem hiding this comment.
const { once } = require('events');
const EventTarget = require('../event-target-implementation')
async function run() {
const et = new EventTarget();
process.nextTick(() => {
et.dispatchEvent('myevent', 42);
});
const [value] = await once(et, 'myevent');
console.log(value);
}
run();@jasnell something like that?
Not sure about this line const EventTarget = require('../event-target-implementation').
Sorry, something went wrong.
There was a problem hiding this comment.
I think we can defer doing that to a future pull request. Mostly this is for web compatibility and for making EE more universal JavaScript compatible but our docs on the other hand mostly ignore that as far as I know.
Sorry, something went wrong.
You did a merge which we typically don't do in Node.js - the process is rather than having a merge commit we do a rebase which places the commits on top of all the commits to this point. The way to go about this would be cherry picking the relevant commits (git cherry-pick COMMIT) on top of checked out master. Alternatively you can just re-apply the changes on top of master (I am not concerned about attribution for my part and you can just re-apply the changes on master). |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM with an example in the docs added
Sorry, something went wrong.
Sorry, something went wrong.
|
@Trott minor on the safe side IMO, this doesn't really introduce an API and could very theoretically break things but in practice shouldn't. This could theoretically be seen as introducing an API. I am also fine with patch. |
Sorry, something went wrong.
Sorry, something went wrong.
PR-URL: #29498 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
PR-URL: #29498 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Notable changes: * crypto: * Add `oaepLabel` option #29489 * deps: * Update V8 to 7.7.299.11 #28918 * More efficient memory handling * Stack trace serialization got faster * The `Intl.NumberFormat` API gained new functionality * For more information: https://v8.dev/blog/v8-release-77 * events: * Add support for `EventTarget` in `once` #29498 * fs: * Expose memory file mapping flag `UV_FS_O_FILEMAP` #29260 * inspector: * New API - `Session.connectToMainThread` #28870 * process: * Initial SourceMap support via `env.NODE_V8_COVERAGE` #28960 * stream: * Make `_write()` optional when `_writev()` is implemented #29639 * tls: * Add option to override signature algorithms #29598 * util: * Add `encodeInto` to `TextEncoder` #29524 * worker: * The `worker_thread` module is now stable #29512
PR-URL: #29498 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Notable changes: * crypto: * Add `oaepLabel` option #29489 * deps: * Update V8 to 7.7.299.11 #28918 * More efficient memory handling * Stack trace serialization got faster * The `Intl.NumberFormat` API gained new functionality * For more information: https://v8.dev/blog/v8-release-77 * events: * Add support for `EventTarget` in `once` #29498 * fs: * Expose memory file mapping flag `UV_FS_O_FILEMAP` #29260 * inspector: * New API - `Session.connectToMainThread` #28870 * process: * Initial SourceMap support via `env.NODE_V8_COVERAGE` #28960 * stream: * Make `_write()` optional when `_writev()` is implemented #29639 * tls: * Add option to override signature algorithms #29598 * util: * Add `encodeInto` to `TextEncoder` #29524 * worker: * The `worker_thread` module is now stable #29512 PR-URL: #29695
Notable changes: * crypto: * Add `oaepLabel` option #29489 * deps: * Update V8 to 7.7.299.11 #28918 * More efficient memory handling * Stack trace serialization got faster * The `Intl.NumberFormat` API gained new functionality * For more information: https://v8.dev/blog/v8-release-77 * events: * Add support for `EventTarget` in `once` #29498 * fs: * Expose memory file mapping flag `UV_FS_O_FILEMAP` #29260 * inspector: * New API - `Session.connectToMainThread` #28870 * process: * Initial SourceMap support via `env.NODE_V8_COVERAGE` #28960 * stream: * Make `_write()` optional when `_writev()` is implemented #29639 * tls: * Add option to override signature algorithms #29598 * util: * Add `encodeInto` to `TextEncoder` #29524 * worker: * The `worker_thread` module is now stable #29512 PR-URL: #29695
|
Really excited to see more browser interop in Node ☺️ One thing that worries me is that this prevents once to listen to error for any kind of interop emitter that implements/extends both EventEmitter and EventTarget (and does so in a minor version). I would have expected the check to be reversed: If the object is a Node EventEmitter, listen to error, otherwise not, but in the shipped version EventTarget is checked for first. I actually kind of would have hoped for Node's EventEmitterr to one day implement EventTarget for interop. I also had a use case for error events on the web come to mind: When you open a WebSocket, you'll want to listen and wait for the open event to know when to start sending messages. If the connection fails during that wait (e.g. the server could not be reached) the error event will fire instead. You'll want to make sure these listeners are also cleaned up properly. The only difference is that it fires an Event object, not an Error object, which in my eyes is enough of an argument to not listen to it in once. |
Sorry, something went wrong.
| // EventEmitters, we do not listen to `error` events here. | ||
| emitter.addEventListener( | ||
| name, | ||
| (...args) => { resolve(args); }, |
There was a problem hiding this comment.
EventTarget is guaranteed to only have one argument, so you could avoid passing an array here.
Sorry, something went wrong.
There was a problem hiding this comment.
@domenic what do you think is the right call API wise in terms of compatibility with EventEmitter and the coming (?) events proposal?
Sorry, something went wrong.
There was a problem hiding this comment.
I wouldn't pay much attention to early-stage TC39 proposals. But I think just compatibility with how events work in event listeners in the DOM would suggest using a single argument instead of an array containing that argument.
Sorry, something went wrong.
There was a problem hiding this comment.
So this now resolves with an array, and just got released in Node v12.11.0. Are we now stuck with this promise signature?
Sorry, something went wrong.
There was a problem hiding this comment.
So this now resolves with an array, and just got released in Node v12.11.0. Are we now stuck with this promise signature?
I think changing that would be a breaking change, yes.
That being said, I think there is some value in keeping this consistent between EventTarget and EventEmitter, so I’m not really sure that we should change this even if we could.
Sorry, something went wrong.
There was a problem hiding this comment.
What about consistency with web EventTarget? If that is a goal, arrays should not get involved.
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
What about consistency with web EventTarget? If that is a goal, arrays should not get involved.
@domenic Yes, there’s a tradeoff, but at least to me a polymorphic API seems worse here than one that performs some unnecessary boxing.
That being said: I personally don’t like the decision to use arrays in the first place, but I think we’re stuck with that now.
Sorry, something went wrong.
There was a problem hiding this comment.
FWIW I'm looking at this and I'm pretty sure Domenic was right and our implementation is wrong. Even for consistency.
Our tests incorrectly use an EventTargetMock that accepts multiple arguments (which isn't possible) and dispatches strings (and not objects).
Sorry, something went wrong.
There was a problem hiding this comment.
Fixed in #33659
Sorry, something went wrong.
|
@felixfbecker that sounds very reasonable to me and was simply missed. @JeniaBR would you be willing to put in the work to change the order so that the API checks if the passed in emitter is a Node EventEmitter first? |
Sorry, something went wrong.
|
@felixfbecker good point! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
My attempt to add support for EventTarget in the once static method.
This PR follow up #27977
Ping @benjamingr please take a look.
Checklist