-
-
Save sanderpick/1249306 to your computer and use it in GitHub Desktop.
window._ = require('underscore'); | |
window.Step = require('step'); | |
window.DNode = require('dnode'); | |
requirejs(['libs/json2', | |
'libs/modernizr-1.7.min', | |
'libs/backbone-min', | |
'libs/store.min'], | |
function () { | |
window.App = { | |
debug: true, | |
start: function () { | |
DNode().connect(function (remote) { | |
try { | |
App.api = remote; | |
App.store = store; | |
App.templator = require('jadeify'); | |
App.publish = require('./minpubsub').publish; | |
App.subscribe = require('./minpubsub').subscribe; | |
App.unsubscribe = require('./minpubsub').unsubscribe; | |
requirejs(['models', 'collections', 'views', 'router', 'backbone-sync'], | |
function (models, collections, views, Router) { | |
App.models = models; | |
App.collections = collections; | |
App.views = views; | |
App.router = new Router(); | |
Backbone.history.start({ | |
pushState: true, | |
silent: true, | |
}); | |
// do something... perhaps, | |
App.publish('AppReady'); | |
}); | |
} catch (err) { | |
console.error('Error in App.start: ' + err + '\n' + err.stack); | |
} | |
}); | |
}, | |
}; | |
requirejs.ready(App.start()); | |
}); | |
sanderpick
commented
Sep 28, 2011
- require() calls are from substack / node-browserify (http://bit.ly/q1YpvW)
- requirejs() calls are from RequireJS (http://requirejs.org/)
How are you using Dnode to sync backbone models?
Looks like App.api is the DNode stub that lets the app carry out "API" calls like App.api.server_method. Do you use this to overwrite Backbone.sync somewhere else?
Yeah 'App.api' refers to remote methods on the server... admittedly, not a very good name but it illustrates the concept... backbone.sync must be overwritten, I've been doing that as a separate file... then requiring it will my models, views, and collections (see latest rev).
Also, I've found having a global handle on the server methods can be useful when you need to do stuff that is not inline with the crud style... as in server-side publishing to client-side subscribers, or vice versa.
Just re-added App.templator - been using Jade (https://github.com/visionmedia/jade) a lot server-side and node-jadeify (https://github.com/substack/node-jadeify) client-side... it gets pretty magical and heavy weight :) The latest Jade has client-side support so jadeify isn't really needed anymore... but I haven't made the switch yet.