Simple module definition tool for Backbone projects
JavaScript CSS
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist
lib
src/backbone
test
.gitattributes
.gitignore
.jshintrc
.travis.yml
BANNER
Gruntfile.js
LICENSE
README.md
index.js
karma.conf.js
package.json

README.md

Backbone.Module

Build Status Dependency Status

Simple module definition tool for Backbone projects.

Dependencies:

Introduction

This project was created to simplify development and assembly large projects. I implemented it as an alternative to asynchronous module definition. It doesn't use XHR or dependency management mechanism, they're just not needed anymore. The library has very small size and doesn't affect size of production code (about 2KB).

Getting Started

Modules definition

You can use one of three available methods to define modules.

Using static constructor.

Backbone.Module(name, callback);

Creating new instance of Backbone.Module.

new Backbone.Module(name, callback);

Using static method define(name, callback).

Backbone.Module.define(name, callback);

Examples

Simple module without dependencies.

Backbone.Module.define('org.app.Model', function () {
    return Backbone.Model;
});

More advanced module with dependencies.

Backbone.Module.define('org.app.Collection', function (require) {
    var Model = require('org.app.Model');

    return Backbone.Collection.extend({
        model: Model
    });
});

Actually don't care in which order you define these modules since you pass a callback functions. They will not be executed in moment of definition. That significantly simplifies build procedure of your project. You don't need to take care about concatenation order your scripts, or manage dependencies.

Callback of org.app.Model will be called in moment of execution require('org.app.Model').

Modules requirement

You can get access to modules using static method require(name).

var Collection = Backbone.Module.require('org.app.Collection');

Callback of org.app.Collection will be called and you will get returned value.

Changelog

0.2.0

  • Completely new plugin's design
  • Dependency injection

0.1.8

  • Renaming project from Backbone.Modules to Backbone.Module
  • Function Backbone.define is now a class Backbone.Module
  • Added CommonJS support

0.1.5

  • Revert 0.1.4 changes

0.1.4

  • Modules have static properties namespace and className

0.1.3

  • Callback-based module definition

0.1.2

  • When absent argument object function define just returns current value

0.1.1

  • New usage method

0.1.0

  • Initial release