@gobistories/gobi-web-integration
Version:
Welcome to Gobi Web Integration. This library will let you put your Gobi stories on your site.
38 lines (36 loc) • 1.25 kB
text/coffeescript
class SimpleEventEmitter
constructor: ->
= {}
on: (eventName, callback) ->
if not .hasOwnProperty eventName
[eventName] = []
listeners = [eventName]
if listeners.indexOf(callback) == -1
listeners.push callback
off: (eventName, callback) ->
if typeof eventName == 'string'
if .hasOwnProperty eventName
if typeof callback == 'function'
eventName, callback
else
[eventName] = []
else
emit: (eventName, eventData, _this) ->
return unless .hasOwnProperty eventName
stack = [eventName]
stackLength = stack.length
i = 0
while i < stackLength
stack[i].call _this or this, eventData
i++
_removeCallback: (eventName, callback) ->
stack = [eventName]
callbackInd = stack.indexOf(callback)
if callbackInd > -1
stack.splice callbackInd, 1
_removeAllCallbacks: ->
for key of
if .hasOwnProperty(key)
delete [key]
module.exports = SimpleEventEmitter