Skip to content

Instantly share code, notes, and snippets.

@bdickason
Created August 13, 2011 12:07
Show Gist options
  • Save bdickason/1143780 to your computer and use it in GitHub Desktop.
Save bdickason/1143780 to your computer and use it in GitHub Desktop.
Event design - client listens directly to object
class enemy extends EventEmitter
load: ->
emit 'load'
move: (location) ->
# moves an enemy across the game
emit 'move', location
class world extends EventEmitter
enemy.on 'load'
# process loading
emit 'loaded', enemy
enemy.move [3, 2]
class client extends EventEmitter
world.on 'loaded', object
# load object data
object.on 'move'
# show enemy moving to the client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment