Skip to content

Instantly share code, notes, and snippets.

@btoll
Created February 23, 2016 15:56
Show Gist options
  • Save btoll/3f6ccc6cd9098b4f5969 to your computer and use it in GitHub Desktop.
Save btoll/3f6ccc6cd9098b4f5969 to your computer and use it in GitHub Desktop.
define [
'underscore'
'backbone'
], (_, Backbone) ->
Emitter = {}
aliases =
un: 'off'
emit: 'trigger'
fire: 'trigger'
fireEvent: 'trigger'
init = (bus) ->
Aggregator = {}
invoke = (method) ->
->
bus[method].apply bus, arguments
for method of bus
Aggregator[method] = invoke method
for method of aliases
Aggregator[method] = invoke aliases[method]
Aggregator.__get = ->
bus
Aggregator
Emitter.addGroup = (group) ->
if not Emitter[group]
bus = init _.extend {}, Backbone.Events
Emitter[group] = bus
Emitter[group]
Emitter.getGroup = (group) ->
Emitter[group]
Emitter.removeGroup = (group) ->
Emitter[group].off()
delete Emitter[group]
Emitter
_.extend Emitter, init(_.extend {}, Backbone.Events)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment