A JavaScript modular library utilising OLOO (objects-linked-to-other-objects) and dependency injection, inspired by https://github.com/getify/You-Dont-Know-JS/blob/master/this%20&%20object%20prototypes/ch6.md#delegation-theory
This library facilitates the chaining together of objects via a modular architecture.
To use mosquitwojs, just drop a single JavaScript file into your page:
<script src="mosquitwo.min.js"></script>
bower install mosquitwojs
A module is a collection of objects. Modules can be injected into other modules to create a component based architecture.
$msq.module(name, [requires]);
$msq.module('module2', []);
$msq.module('module1', ['module2']);
var module = $msq.module('module2');
A linked object is just a standard JavaScript object with declaration parameters enabling various linking features.
module.linkedObject(name, linkedObject, params);
module.linkedObject('object2', {
init: function() {
console.info('hello');
}
});
var linkedObject = module.linkedObject('object2');
module.linkedObject('object2', {
init: function() {
console.info('hello');
}
}, {
internal: true,
toBeLinked: true,
linkedTo: 'object3',
observableMethods: ['method1', 'method2']
});
When accessing the defined object, it will be linked to this linked object
The linked object can not be directly accessed. It must be linked to another linked object.
The linked object can only be accessed from within another linked objected within the same module.
Register methods to be observed and executed by executing the $next method. See Observable Methods below
The ability to inject linkedObjects into functions.
$msq.$inject([named object list, function]);
module.linkedObject('object2', {
init: $msq.$inject(['object1', function(object1){
object1.log('hello');
}])
});
These can be defined at both at the global and modular level and specify objects which will be linked to every linked object created at either the global or modular level.
$msq.$baseLinkedObject(object);
module.$baseLinkedObject(object);
$msq.baseLinkedObject({
baseItem1: 'item1'
});
module.baseLinkedObject({
modularBaseItem1: 'item1'
});
Observable Methods permit many functions, across many linkedObjects, with the same name to be executed by just calling the $next method. Methods must be registered and an instance of the hosting linked object created, before the method will be called.
This can either be done using the params option as stated above or by using the $observe method from within a linked object.
$observe(linkedObjectName, methodName);
This can only be done using the $unobserve method from within a linked object.
$unobserve(linkedObjectName, methodName);
This will execute all registered instances of the specified method.
$next(methodName, optional parameter);