Minimalistic dependency injection library for browser. For those who still use browser globals and don't want AMD or Commonjs in their project.
For quick introduction see the
examples
folder.
Get library with minimalistic API that allow to define frontend modules in order-agnostic style. This allows to concatenate all modules into single file with mask like this app/*.js
Include module.min.js above your modules.
Better: Bundle you libraries into one file vendor.js
with dependent order, including module package, bundle your own modules into one file app.js
. Include both like so:
<script src="/js/vendor.js"></script>
<script src="/js/app.js"></script>
Define a module.
module('task', ['user'], function (user) {
return {
createOne: function () {
// if (user.isLoggedIn()) {...
}
}
});
module('user', function () {
return {
isLoggedIn: function () {
//
}
}
});
Require a module (it is best practice to avoid this).
module('main').initialize();
Usually you define module called main
with function initialize()
that will automatically bootstrap the application.
Execute following if you want to bootstrap you application manually.
module.autorun(false);
// you don't need to call it like that
// module.autorun(true);
// as it's default behavior
Return object where all modules collected and set global one named like so: module1417559110777
that means module
+ timestamp.
Can be used for debugging purpose only, do not access to modules directly.
module.debug();
Return instance of module and release window.module
namespace to its initial value.
var di = module.noConflict();
di('user', function () {
return {
isLoggedIn: function () {
//
}
}
});
Any module should be define synchronously. In other words no setTimeout/AJAX-dependent module definitions.
- document code
- add unit tests
- add easy shim method