Giter Site home page Giter Site logo

Add events.once about events HOT 9 CLOSED

browserify avatar browserify commented on July 19, 2024 2
Add events.once

from events.

Comments (9)

vweevers avatar vweevers commented on July 19, 2024 5

You can pretty much copy https://github.com/nodejs/node/pull/26078/files, there have been no changes to the once function since that PR

from events.

vvscode avatar vvscode commented on July 19, 2024 1

@goto-bus-stop as far as I see - there is already some .once implementation. And the existing one is incompatible with a new description

https://github.com/Gozala/events/blob/master/tests/once.js

from events.

vweevers avatar vweevers commented on July 19, 2024 1

@vvscode That's require('events').EventEmitter.prototype.once, rather than require('events').once

from events.

goto-bus-stop avatar goto-bus-stop commented on July 19, 2024 1

Yes, there is already a EventEmitter.prototype.once method that adds an event listener:

var emitter = new EventEmitter()
emitter.once('xyz', function (arg1, arg2) {
})

This is for the new EventEmitter.once method that returns a Promise instead:

var emitter = new EventEmitter()
var [arg1, arg2] = await EventEmitter.once(emitter, 'xyz')

from events.

goto-bus-stop avatar goto-bus-stop commented on July 19, 2024 1

We don't have any build system for events.js. The tests are bundled using browserify but without babel or anything, so they should work in old browsers as much as possible (eg always use .then() instead of await).

The goal is to have identical behaviour to Node.js, so I think our tests should at least be based on Node's. they can be rewritten a bit (and have to be ported to older JS) but they should test the same functionality.

from events.

goto-bus-stop avatar goto-bus-stop commented on July 19, 2024 1

@Doogiemuc hmm, I don't see it? that would break the entire ecosystem so I hope they wouldn't do that :)
There are two .once() functions: the long-time emitter.once(eventName, callback) method and the newer EventEmitter.once(emitter, eventName) associated function.

from events.

vweevers avatar vweevers commented on July 19, 2024 1

It really should have gotten a distinct name 😄

from events.

vvscode avatar vvscode commented on July 19, 2024

Ok. A frew more questions - don't you use any build system for https://github.com/Gozala/events/blob/master/events.js ?

Is it required copy-paste tests or I can write to them by myself?

from events.

Doogiemuc avatar Doogiemuc commented on July 19, 2024

Most recent version of NodeJS v12.10.0 changed the order of arguments for theoncemethod: https://nodejs.org/api/events.html

from events.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.