Code Monkey home page Code Monkey logo

Comments (6)

manuelroemer avatar manuelroemer commented on June 2, 2024 1

The main problem / issue that I see is that right now the chaining on an "api" works also with the full API

Ah, I see. I do think though that this is not really "known"/used because TS, at the very least, says that the result is an EventEmitter, not the full API. But fair point.

from piral.

FlorianRappl avatar FlorianRappl commented on June 2, 2024

Well bind works or alternatively, you could also make it another lambda ((...args) => events.once(...args)). I think going for the bind is great - let's do that!

Alternatively, let's check the implementation and maybe once can be done in a way that does not require this (and let's check that the others don't suffer from this problem; I think they don't).

from piral.

manuelroemer avatar manuelroemer commented on June 2, 2024

Alternatively, let's check the implementation and maybe once can be done in a way that does not require this (and let's check that the others don't suffer from this problem; I think they don't).

The others don't seem to have the same problem. I think the only issue that might arise for them in this scenario is that method chaining might be broken. They return this, for example in on:

on(type, callback) {
  // ...
  return this;
}

So, if you were to do on('foo', handler).once('bar', handler) or something similar, you might run into issues.

I think going for the bind is great - let's do that!

Great, sounds like a plan! I'll tackle it.

from piral.

FlorianRappl avatar FlorianRappl commented on June 2, 2024

Yeah with the chaining in mind I'd actually improve the basis for this.

We should have the events properly captured.

from piral.

FlorianRappl avatar FlorianRappl commented on June 2, 2024

Instead of

return {
  on() {
    // ...
    return this;
  },
  // ...
}

we'd go for

const events = {
  on() {
    // ...
    return events;
  },
  // ...
};
return events;

The main problem / issue that I see is that right now the chaining on an "api" works also with the full API - while with this approach it only works on a subset (events).

from piral.

FlorianRappl avatar FlorianRappl commented on June 2, 2024

Ah, I see. I do think though that this is not really "known"/used because TS,

Yes - otherwise it would have been a breaking change.

from piral.

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.