Skip to content

Instantly share code, notes, and snippets.

@michaelcontento
Created July 3, 2011 19:50
Show Gist options
  • Save michaelcontento/1062545 to your computer and use it in GitHub Desktop.
Save michaelcontento/1062545 to your computer and use it in GitHub Desktop.
Backbone models connected with Faye based backend (frontend written in CoffeeScript)
$ ->
# === CONFIGURATION
GAME_DIV_ID = '#game'
FAYE_URL = 'http://localhost:9292/faye'
# === APPLICATION
GameModel = Backbone.Model.extend {}
GameView = Backbone.View.extend {
el: $(GAME_DIV_ID)
templates: window.JST
events: {}
initialize: ->
_.bindAll @, 'render'
@model.bind 'change', @render
render: ->
state = @model.get 'state'
content = @templates[state] @model.attributes
$(@el).html content
@
}
# === SETUP-GLUE
start_game = ->
game = new GameModel()
app = new GameView model: game
faye = new Faye.Client FAYE_URL
faye.subscribe '/**', (message) ->
console.log 'FAYE'
game.set message
# === START CONDITION
start_game() if $(GAME_DIV_ID)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment