olorin
Version:
CoffeeScript Myo Bindings
48 lines (32 loc) • 1.07 kB
text/coffeescript
_ = require('underscore')
class Subscription
constructor: (, , ) ->
invoke: (args...)->
dispose: ->
.splice(, 0)
class Events
constructor: () ->
= {}
on: (eventName, listener) ->
if ![eventName]
![eventName] = [] # new subscription list for this new event
subscriptionList = [eventName]
subscription = new Subscription(listener, subscriptionList.length, subscriptionList)
subscriptionList.push(subscription)
return subscription
trigger: (eventName, args...) ->
subscriptionList = [eventName] || []
len = subscriptionList.length
while len--
subscription = subscriptionList[len]
subscription.invoke(args...)
off: (eventName) ->
[eventName] = []
class Event
constructor: (, ) ->
_.extend(exports, {
Event: Event
Events: Events
Subscription: Subscription
})