Skip to content

Instantly share code, notes, and snippets.

@jeffrydegrande
Created January 5, 2013 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffrydegrande/4463009 to your computer and use it in GitHub Desktop.
Save jeffrydegrande/4463009 to your computer and use it in GitHub Desktop.
class Event
@on: (event, fn)->
$('body').bind event, (_, data) -> fn(data)
@trigger: (event, data)->
$('body').trigger(event, [data])
class Ajax
@getJSON: (url, event)->
$.getJSON url, (data)->
Event.trigger(event, data)
# domain specific functions, goes in in apropriate modules
class Tracker
@fetch: -> Ajax.getJSON "/current_positions", "trackers:ready"
class ReferencePoint
@fetch: -> Ajax.getJSON "/reference_points", "reference_points:ready"
doSomethingWith = (map, data)-> console.log "#{map} #{data}"
doSomethingElseWith = (map, data)-> console.log "Holy Shit"
$ ->
setupMap (map)->
Event.on 'trackers:ready', (trackers)->
doSomethingWith(map, trackers)
Event.on 'trackers:ready', (trackers)->
doSomethingElseWith(map, trackers)
Event.on 'reference_points:ready', (referencePoints)->
doSomethingWith(map, referencePoints)
# kick off by loading data
Tracker.fetch()
ReferencePoint.fetch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment