Created
April 11, 2014 16:27
-
-
Save tomz/10482076 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
(-> | |
slice = Array::slice | |
@events = | |
events: {} | |
on: (topic, handler, context) -> | |
context = this unless context? | |
@events[topic] = @events[topic] or [] | |
@events[topic].push | |
handler: handler | |
context: context | |
trigger: (topic) -> | |
return unless @events[topic]? | |
args = slice.apply(arguments_, 1) | |
i = 0 | |
l = @events[topic].length | |
event = undefined | |
while i < l | |
event = @events[topic][i] | |
event.handler.apply event.context, args | |
i++ | |
).call this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment