-
-
Save jjt/40c70d97546da131b62f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
Port of MicroEvent in Coffeescript with some naming modifications | |
and a new 'once' method. | |
Original project: | |
https://github.com/jeromeetienne/microevent.js | |
### | |
class MicroEvent | |
_init:-> @_listn or @_listn = {} | |
_create:(e)-> @_init()[e] or @_init()[e] = [] | |
on:(e, f)-> (@_create e).push f | |
off:(e, f)-> (t.splice (t.indexOf f), 1) if (t = @_init()[e])? | |
once:(e, f)-> @on e, (t = => (@off e, t) && f.apply @, arguments) | |
emit:(e)-> l.apply @, ([].slice 1) for l in t if (t = @_init()[e])?; 0 | |
@mixin=(t)-> t::[p] = @::[p] for p of @::; 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment