Skip to content

Instantly share code, notes, and snippets.

@sanderpick
Created September 28, 2011 21:27
Show Gist options
  • Save sanderpick/1249306 to your computer and use it in GitHub Desktop.
Save sanderpick/1249306 to your computer and use it in GitHub Desktop.
main.js
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
Copy link
Author

@javisantana
Copy link

How are you using Dnode to sync backbone models?

@tokumine
Copy link

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?

@sanderpick
Copy link
Author

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).

@sanderpick
Copy link
Author

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.

@sanderpick
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment