Skip to content
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

[feature request] once handler #54

Closed
Andarist opened this issue May 10, 2017 · 3 comments
Closed

[feature request] once handler #54

Andarist opened this issue May 10, 2017 · 3 comments

Comments

@Andarist
Copy link
Contributor

would u consider adding this or is it out of scope? Ive tried implementing it myself so I could send a PR, but my minifications skill are not that great ;)

best result i got was 214B which is exceeding ur goal

@tunnckoCore
Copy link
Collaborator

tunnckoCore commented May 10, 2017

A lot of things and implementations were declined because that strict limit, so probably no.

You might be interested in https://github.com/tunnckocore/dush, which is around ~300-400b, with all needed things, and can have micro plugins. I needed .once and such things (like #12 "chaining" which you can remove with plugin), that's why it exists.

@rangermeier
Copy link

rangermeier commented Mar 6, 2020

As reference for anyone looking for this functionality: It's possible to add a once method at runtime:

const emitter = mitt()
emitter.once = (type, handler) => {
    const wrappedHandler = (evt) => {
        handler(evt)
        emitter.off(type, wrappedHandler)
    }
    emitter.on(type, wrappedHandler)
}

@plehnen
Copy link

plehnen commented Aug 19, 2020

@rangermeier this will not work when you try to unregister the handler via .off() before it was called at least "once".
(e.g. if you open a dialogue and register the once handler, close it and unregister with off, and re-open and again register with once. Once the event is emitted, the handler will now be called twice!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants