Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mathieuancelin/modules.js
lightweight modules manager for JavaScript
https://github.com/mathieuancelin/modules.js
Last synced: 3 days ago
JSON representation
lightweight modules manager for JavaScript
- Host: GitHub
- URL: https://github.com/mathieuancelin/modules.js
- Owner: mathieuancelin
- Created: 2013-01-07T14:51:45.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-01-07T22:08:59.000Z (almost 12 years ago)
- Last Synced: 2023-03-11T09:56:31.049Z (over 1 year ago)
- Language: JavaScript
- Size: 199 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Modules.js
===================A lightweight modules manager for JavaScript. Don't handle scripts loading.
Use can use it like that :
```javascript
var FooBar = Modules.define('play.foo.bar', function() {
return {
hello: function(name) { return ("Hello " + name + "!"); }
};
});Modules.use('play.foo.bar', function(fb) {
console.log(fb.hello('foobar'));
});console.log(FooBar.hello('foobar'));
var Bar = Bar || Modules.get('play.foo.bar');
console.log(Bar.hello('foobar'));Modules.create('ModuleA', function(ModuleA) {
ModuleA.hello = function() {
console.log("Hello from module A");
};
ModuleA.setupModule = function() {
console.log("Setup ModuleA");
};
ModuleA.messageReceived = function(msg) {
console.log("Received in ModuleA %s", msg);
};
});Modules.create('ModuleA:1.0', function(ModuleA) {
ModuleA.hello = function() {
console.log("Hello from module A v 1.0");
};
ModuleA.setupModule = function() {
console.log("Setup ModuleA v 1.0");
};
ModuleA.messageReceived = function(msg) {
console.log("Received in ModuleA v 1.0 %s", msg);
};
});Modules.create('ModuleA:2.0', function(ModuleA) {
ModuleA.hello = function() {
console.log("Hello from module A v 2.0");
};
ModuleA.setupModule = function() {
console.log("Setup ModuleA v 2.0");
};
ModuleA.messageReceived = function(msg) {
console.log("Received in ModuleA v 2.0 %s", msg);
};
});Modules.define('ModuleB', function() {
return {
hello: function() {
console.log("Hello from module B");
},
moduleReady: function() {
console.log("ModuleB is ready !!!");
},
messageReceived: function(msg) {
console.log("Received in ModuleB %s", msg);
}
};
});Modules.createWithDependencies('ModuleC', ['ModuleA', 'ModuleB'], function(ModuleC, ModuleA, ModuleB) {
ModuleC.hello = function() {
ModuleA.hello();
ModuleB.hello();
console.log("Hello from module C");
};
ModuleC.messageReceived = function(msg) {
console.log("Received in ModuleC %s", msg);
};
});Modules.defineWithDependencies('ModuleD', ['ModuleC', 'get'], function(ModuleC, get) {
return {
hello: function() {
ModuleC.hello();
console.log("Hello from module D");
},
messageReceived: function(msg) {
console.log("Received in ModuleD %s", msg);
get('ModuleA').hello();
}
};
});Modules.initModules();
Modules.use('ModuleD', function(ModuleD) {
ModuleD.hello();
});
Modules.uses(['ModuleA', 'ModuleB', 'ModuleC', 'ModuleD'], function(ModuleA, ModuleB, ModuleC, ModuleD) {
ModuleA.hello();
ModuleB.hello();
ModuleC.hello();
ModuleD.hello();
});Modules.broadcast("Hello Modules ...");
Modules.sendToModule('ModuleA', 'Hello ModuleA ...');
Modules.sendToModules(['ModuleA', 'ModuleB'], 'Hello ModuleA and ModuleB ...');
Modules.sendToModulesMatching(/Module[A-B]/i, 'Hello Module matching AB...');
Modules.sendToModulesMatching(/Module[C-D]/i, 'Hello Module matching CD...');Modules.sendToModulesMatching(/Module[A-Z]:[0-9*]\.[0-9*]/i, 'Hello versioned Modules ...');
Modules.sendToModulesMatching(/Module[A-z]:1\.[0-9*]/i, 'Hello Modules in v 1.x ...');
Modules.sendToModulesMatching(/Module[A-Z]:2\.[0-9*]/i, 'Hello Modules in v 2.x ...');Modules.use('jquery', function(jqy) {
jqy('#messages').html('Hello');
});Modules.use('underscore', function(udsc) {
udsc.each(['1','2'], function(item) {
console.log(item);
});
});define('A', function() {
return {
hello: function() { console.log('Hello'); }
};
});define('B', ['A'], function(A) {
return {
hello: function() { A.hello(); console.log('Hello'); }
};
});require(['A'], function(A) {
A.hello();
});require(['A', 'B'], function(A, B) {
B.hello();
});```