Backbone RequireJs module name spacing and application structure.

Web Applications using Backbone and RequireJs produce rich client-applications. Both the open-source libraries are very useful for rapid  structured web applications development.

Backbone 

Backbone  helps you to organize your code properly and will be very helpful and easy when you are reusing it. Basic purpose is to build applications in MVC pattern.


RequireJs

RequireJs is a module loader, improve speed and quality and code. It supports to load modules asynchronously. In other words it is for  AMD(Asynchronous Module definitions) .

The critical part in building web applications using these libraries is application structure. How to organize modules as well as Models,Collections,Views and Controllers is complex part.

Here we will go with sample 

var App = window.App || {};

application should have some global context for that, add status.

App.status = {};

Working with Backbone, create Models, Collections, Views and Routers using namespaces.

App.Models = {};
App.Views = {};
App.Collections = {};
App.Routers = {};

Then, the main part of organizing  modules and initializing.

For example application contains 3 modules named (users, books , stores), lets construct backbone classes using module naming.

App.users = {};  //for users module

//creating users class accessible under App using users module name
App.users.appUsers = new App.Collections.users;

Similarly for construct all the models and collections under respective module naming

App.books = {}; // books module
App.stores = {}; //stores module

Next separate all user interface classes and construct using ui part in App.

App.ui = {}; //all the applications views

//creating books container
App.ui.BooksContainer = App.Views.BooksMasterView;


Final part of application is controlling application modules. Construct all the router under controllers namespace of App.

App.controllers = {};

//creating application master router
 App.controllers.master = App.Routers.MasterRouter;

Conclusion

       Applications  should expose all parts the body. Global namespacing provides rich interface for building high end applications. Both RequireJs and BackboneJs libraries gives a structured format but using two at a time  needs simple attention. The above structural organization of modules in MVC pattern explores Application usage. 





Share this

Related Posts

Previous
Next Post »