Created
July 3, 2011 19:50
-
-
Save michaelcontento/1062545 to your computer and use it in GitHub Desktop.
Backbone models connected with Faye based backend (frontend written in CoffeeScript)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ -> | |
# === 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