Skip to content

Instantly share code, notes, and snippets.

@ORESoftware ORESoftware/main.js
Last active Sep 18, 2015

Embed
What would you like to do?
config
// the # and @ notation is mine just to identify certain modules as my own and to make it easier to grep for things
// as you can see in the bottom of the file, RequireJS loads all dependencies in app/js/application before starting the app
// so if you put #allViews, #allCSS and #allTemplates as dependencies of your app/js/application module then this allows us to preload certain dependences so that we can later use *synchronous* require calls
// the synchronous require calls will allow us to do hot reloading with React and Backbone. We *could* make the render functions asynchronous, but there are two problems with that
// one problem is that Backbone conventions recommend returning 'this' from render(), the second is that React needs you return a valid React component from render, so render has to be synchronous
requirejs.config({
enforceDefine: false,
waitSeconds: 7,
baseUrl: '/static',
paths: {
'async': 'vendor/async',
'jquery': 'vendor/jquery',
'util(NPM)': 'vendor/util',
'ejs': 'vendor/ejs',
'flux': 'vendor/Flux',
'text': 'vendor/text',
'form2js': 'vendor/form2js',
'underscore': 'vendor/underscore-min',
'ijson': 'vendor/idempotent-json',
'backbone': 'vendor/backbone',
'bootstrap': 'vendor/bootstrap',
'backbone-validation': 'vendor/backbone-validation-amd',
'observe': 'vendor/observe',
'react': 'vendor/react-with-addons',
'socketio': 'vendor/socketio',
'events': 'vendor/events-amd',
'@eventBus': 'app/js/eventBuses/routerEventBus',
'#Adhesive': 'app/js/adhesive/Adhesive',
'@hotReloader': 'app/js/hot-reloading/hotReloader',
'*jsPatches': 'app/js/patches/jsPatches',
'*backbonePatches': 'app/js/patches/backbonePatches',
'*windowPatches': 'app/js/patches/windowPatches',
'+appState': 'app/js/state/appState',
'+viewState': 'app/js/state/viewState',
'#allTemplates': 'app/js/meta/allTemplates',
'#allViews': 'app/js/meta/allViews',
'#allModels': 'app/js/meta/allModels',
'#allCollections': 'app/js/meta/allCollections',
'#allControllers': 'app/js/meta/allControllers',
'#allDispatchers': 'app/js/meta/allDispatchers',
'#allCSS': 'app/js/meta/allCSS',
'#allFluxActions': 'app/js/meta/allFluxActions',
'#allFluxConstants': 'app/js/meta/allFluxConstants',
'@oplogSocketClient': 'app/js/oplogSocketClient',
'@BaseCollection': 'app/js/collections/BaseCollection',
'@SuperController': 'app/js/controllers/SuperController',
'@AppDispatcher': 'app/js/flux/dispatcher/AppDispatcher',
'@Router': 'app/js/routers/router'
},
'shim': {
'underscore': {
'exports': '_'
},
'backbone': {
'deps': ['jquery', 'underscore'],
'exports': 'Backbone'
},
ejs: {
exports: "ejs"
}
}
});
define('START', ['backbone','jQuery'], function () {
//we want jQuery and Backbone to both be loaded first before anything else
require(['app/js/application'], function (Application) {
Application.start();
});
});
require(['START']); //this requires the START module above, normally we put an AMD module defined by 'define' it's own file, but we make an exception for the above
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.