Git Product home page Git Product logo

Comments (8)

developit avatar developit commented on June 19, 2024 3
let all = {}
let events = mitt(all)

events.reset = () => {
  for (let i in all) delete all[i]
}

let off = events.off
events.off = (type, handler) => {
  if (!handler) delete all[type]
  else return off(type, handler)
}

from mitt.

ZhouHansen avatar ZhouHansen commented on June 19, 2024 3

thx, makes me to keep using mitt.

from mitt.

dotproto avatar dotproto commented on June 19, 2024 2

I'm going to crib @tunnckoCore's answer on #54 and suggest that you take a look at dush. Mitt has a very strict 200 byte limit, so adding features is a real challenge. Dush already has the behavior you described and is only slightly larger.

from mitt.

developit avatar developit commented on June 19, 2024 1

ah, I only read the issue title. Added another option.

from mitt.

ZhouHansen avatar ZhouHansen commented on June 19, 2024

thx

from mitt.

tunnckoCore avatar tunnckoCore commented on June 19, 2024

Yep. It is simple reset here.

edit: @developit, your case is for removing just all handlers, but not just all of some type like .off('foo'). :)

from mitt.

mehdi-cit avatar mehdi-cit commented on June 19, 2024

I went for a slightly different version. Disposing of reset and adding a line to the overridden off:

events.off = (type, handler) => {
  if(!type) {all ={}; return;}  
  if (!handler) delete all[type]
  else return off(type, handler)
}

from mitt.

tunnckoCore avatar tunnckoCore commented on June 19, 2024

@ZhouHansen @mehdi-cit, in any way you add bytes, so it not make any sense to me to do that instead of just using dush, which is exactly because of this 100-200 bytes bigger than mitt.

Closing, since solutions are found.

from mitt.

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.