Adding Hydra.js 3.1.2

This commit is contained in:
tcorral
2013-02-20 19:47:57 +01:00
parent 91bb3c627d
commit ca0ed3686c
6 changed files with 49 additions and 377 deletions
-179
View File
@@ -1,179 +0,0 @@
# Hydra.js
Hidra.js is a module manager oriented system.
## Updated to version 3.1.1
[Changelog](https://raw.github.com/tcorral/Hydra.js/master/changelog.txt)
## Description
Hydra.js is the library that will help you to scale your app.
Hydra.js is a framework that gives you the tools to write your application using modules or widgets and make easy to work with them.
Hydra.js uses a decoupled architecture that:
* Allows you to change your base framework without change the modules or widget code.
* Allow the modules communicate with each other without knowing which modules are loaded.
* Can be easily extended with new features.
### Some benefits:
* No known module to other modules
* If something is wrong in one module, the other modules will continue working.
* Notifying an action will be called on all the modules that will be listening this action.
* A module can be extended
* If you have a module that is working well you can extend it to change his behavior without losing is original behavior.
* Allows multi-instance modules
* Allows set private variables to be used inside of modules.
* Can be used in url threaded application as in an Ajax threaded application.
* You can test your modules with any Unit Testing Framework.
* Only 2.37KB when [Gzipped](https://github.com/tcorral/Hydra.js/raw/master/versions/hydra.min.js.gz) 2.83KB if you add BasicErrorHandler and Deferred plugins.
[Project Web](http://tcorral.github.com/Hydra.js)
[API documentation](http://tcorral.github.com/Hydra.js/apis/Hydra.js_API_v3.1.0/index.html)
[Examples](http://tcorral.github.com/Hydra.js/examples/index.html) to see for yourself!
## Usage
### Before using it:
Insert in your code:
<script type="text/javascript" src="/path/to/your/js/libs/Hydra.js"></script>
### Setting variables
Hydra.module.setVars({
gaq: _gaq,
list: document.getElementById( "list" )
});
Setting the variables in this way this variables will be accessible as the last argument in init module method if needed you can access
to this variables object using getVars (See 'Getting variables')
*Tip. This method not only set variables, if the object has been set before the new variables will be merged with the previous object. *
### Getting variables
var oVars = Hydra.module.getVars();
Returns the object with the private variables set using setVars (See 'Setting variables')
### Create a module
Hydra.module.register( 'moduleId', function( bus )
{
return {
init: function ( oData ) {}
};
});
### Extend a module overriding the base module
To extend a module you will need to register the base module before extends it.
Hydra.module.extend( 'moduleId', function( bus )
{
return {
init: function ( oData ) {}
};
});
### Extend a module creating a new module
To extend a module you will need to register the base module before extends it.
Hydra.module.extend( 'moduleId', 'newModuleId', function( bus )
{
return {
init: function ( oData ) {}
};
});
This extension allows access the parent methods as classical inheritance.
### Access parent methods
Register base module:
Hydra.module.register( 'moduleId', function( bus )
{
return {
init: function ( oData ) {},
changeTitle: function( sTitle ){
document.title = sTitle;
}
};
});
Create the new module using "extend":
Hydra.module.extend( 'moduleId', 'newModuleId', function( bus )
{
return {
init: function ( oData ) {},
changeTitle: function( sTitle ){
sTitle += " " + new Date().getTime();
// This is the way of access parent methods.
this.__super__.call( "changeTitle", [sTitle] );
}
};
});
#### When listening events
Hydra.module.register( 'moduleId', function( bus )
{
return {
events : {
'channel: {
'item:action1': function ( oData ) {}
}
},
init: function ( oData ) {
/* The subscribing of events is done by Hydra inside the core.
* bus.subscribe( this );
*/
}
};
});
### Publishing actions
To use the action manager you have accessible using "bus".
The publish method expect three arguments, but only the first two are mandatory, the channel name and the event name
Hydra.bus.publish( 'channel_name', 'event_name', data );
*Tip: 'global' channel is created by default to use it if you want to communicate with other modules that are not related with a specific channel. *
Hydra.module.register( 'moduleId', function( bus )
{
return {
events : {
'channel: {
'item:action1': function ( oData ) {}
}
},
init: function ( oData ) {
$( "#button" ).click( function(){
bus.publish( 'channel', 'item:action1', {} );
});
}
};
});
If you need compatibility with the previous event manager called Action, you can add it in your code to maintain compatibility with previous version's code. You can download it from: [Action](https://github.com/tcorral/Hydra_Extensions/tree/master/Sandbox)
## Documentation
[Project Web](http://tcorral.github.com/Hydra.js)
[API documentation](http://tcorral.github.com/Hydra.js/apis/Hydra.js_API_v2.5.0/index.html)
[Examples](http://tcorral.github.com/Hydra.js/examples/index.html) to see for yourself!
## License
Hydra.js is licensed under the MIT license.
## Agreements
Hydra was inspired by Nicholas Zakas presentation.
* [Scalable Javascript Application](http://www.slideshare.net/nzakas/scalable-javascript-application-architecture)
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
/*global exports, module, require, define, setTimeout*/
(function () {
'use strict';
var root, sNotDefined, oModules, oVars, _null_, bUnblockUI, _false_, sVersion, Hydra, bDebug, ErrorHandler, Module, Bus, oChannels, isNodeEnvironment, oObjProto;
var root, sNotDefined, oModules, oVars, _null_, bUnblockUI, _false_, sVersion, FakeModule, Hydra, bDebug, ErrorHandler, Module, Bus, oChannels, isNodeEnvironment, oObjProto;
/**
* Used to generate an unique key for instance ids that are not supplied by the user.
@@ -91,7 +91,7 @@
* @private
* @type {String}
*/
sVersion = '3.1.1';
sVersion = '3.1.2';
/**
* Used to activate the debug mode
@@ -279,6 +279,7 @@
return aSubscribers;
}
/**
* Bus is the object that must be used to manage the notifications by channels
* @constructor
@@ -609,10 +610,8 @@
* @return {Module}
*/
register:function (sModuleId, fpCreator) {
oModules[sModuleId] = {
creator:fpCreator,
instances:{}
};
var self = this;
oModules[sModuleId] = new FakeModule(sModuleId, fpCreator);
return oModules[sModuleId];
},
/**
@@ -722,17 +721,15 @@
oExtendedModule = fpCreator(Bus);
oBaseModule = oModule.creator(Bus);
oModules[sFinalModuleId] = {
creator:function (Bus) {
// If we extend the module with the different name, we
// create proxy class for the original methods.
oFinalModule = self._merge(oBaseModule, oExtendedModule);
// This gives access to the Action instance used to listen and notify.
oFinalModule.__action__ = Bus;
return oFinalModule;
},
instances:{}
};
oModules[sFinalModuleId] = new FakeModule(sFinalModuleId, function (Bus) {
// If we extend the module with the different name, we
// create proxy class for the original methods.
oFinalModule = self._merge(oBaseModule, oExtendedModule);
// This gives access to the Action instance used to listen and notify.
oFinalModule.__action__ = Bus;
return oFinalModule;
});
return oModules[sFinalModuleId];
},
/**
* Method to set an instance of a module
@@ -970,6 +967,39 @@
}
};
/**
* Module to be stored, adds two methods to start and extend modules.
* @private
* @param {String} sModuleId
* @param {Function} fpCreator
* @constructor
*/
FakeModule = function(sModuleId, fpCreator)
{
if(typeof fpCreator === sNotDefined)
{
console.log('test');
}
this.creator = fpCreator;
this.instances = {};
this.sModuleId = sModuleId;
};
FakeModule.prototype = {
start: function(oData)
{
return Module.prototype.start(this.sModuleId, undefined, oData);
},
extend: function(oSecondParameter, oThirdParameter)
{
return Module.prototype.extend(this.sModuleId, oSecondParameter, oThirdParameter);
},
stop: function()
{
Module.prototype.stop(this.sModuleId);
}
};
/**
* getErrorHandler is a method to gain access to the private ErrorHandler constructor.
* @private
File diff suppressed because one or more lines are too long
-179
View File
@@ -1,179 +0,0 @@
# Hydra.js
Hidra.js is a module manager oriented system.
## Updated to version 3.1.1
[Changelog](https://raw.github.com/tcorral/Hydra.js/master/changelog.txt)
## Description
Hydra.js is the library that will help you to scale your app.
Hydra.js is a framework that gives you the tools to write your application using modules or widgets and make easy to work with them.
Hydra.js uses a decoupled architecture that:
* Allows you to change your base framework without change the modules or widget code.
* Allow the modules communicate with each other without knowing which modules are loaded.
* Can be easily extended with new features.
### Some benefits:
* No known module to other modules
* If something is wrong in one module, the other modules will continue working.
* Notifying an action will be called on all the modules that will be listening this action.
* A module can be extended
* If you have a module that is working well you can extend it to change his behavior without losing is original behavior.
* Allows multi-instance modules
* Allows set private variables to be used inside of modules.
* Can be used in url threaded application as in an Ajax threaded application.
* You can test your modules with any Unit Testing Framework.
* Only 2.37KB when [Gzipped](https://github.com/tcorral/Hydra.js/raw/master/versions/hydra.min.js.gz) 2.83KB if you add BasicErrorHandler and Deferred plugins.
[Project Web](http://tcorral.github.com/Hydra.js)
[API documentation](http://tcorral.github.com/Hydra.js/apis/Hydra.js_API_v3.1.0/index.html)
[Examples](http://tcorral.github.com/Hydra.js/examples/index.html) to see for yourself!
## Usage
### Before using it:
Insert in your code:
<script type="text/javascript" src="/path/to/your/js/libs/Hydra.js"></script>
### Setting variables
Hydra.module.setVars({
gaq: _gaq,
list: document.getElementById( "list" )
});
Setting the variables in this way this variables will be accessible as the last argument in init module method if needed you can access
to this variables object using getVars (See 'Getting variables')
*Tip. This method not only set variables, if the object has been set before the new variables will be merged with the previous object. *
### Getting variables
var oVars = Hydra.module.getVars();
Returns the object with the private variables set using setVars (See 'Setting variables')
### Create a module
Hydra.module.register( 'moduleId', function( bus )
{
return {
init: function ( oData ) {}
};
});
### Extend a module overriding the base module
To extend a module you will need to register the base module before extends it.
Hydra.module.extend( 'moduleId', function( bus )
{
return {
init: function ( oData ) {}
};
});
### Extend a module creating a new module
To extend a module you will need to register the base module before extends it.
Hydra.module.extend( 'moduleId', 'newModuleId', function( bus )
{
return {
init: function ( oData ) {}
};
});
This extension allows access the parent methods as classical inheritance.
### Access parent methods
Register base module:
Hydra.module.register( 'moduleId', function( bus )
{
return {
init: function ( oData ) {},
changeTitle: function( sTitle ){
document.title = sTitle;
}
};
});
Create the new module using "extend":
Hydra.module.extend( 'moduleId', 'newModuleId', function( bus )
{
return {
init: function ( oData ) {},
changeTitle: function( sTitle ){
sTitle += " " + new Date().getTime();
// This is the way of access parent methods.
this.__super__.call( "changeTitle", [sTitle] );
}
};
});
#### When listening events
Hydra.module.register( 'moduleId', function( bus )
{
return {
events : {
'channel: {
'item:action1': function ( oData ) {}
}
},
init: function ( oData ) {
/* The subscribing of events is done by Hydra inside the core.
* bus.subscribe( this );
*/
}
};
});
### Publishing actions
To use the action manager you have accessible using "bus".
The publish method expect three arguments, but only the first two are mandatory, the channel name and the event name
Hydra.bus.publish( 'channel_name', 'event_name', data );
*Tip: 'global' channel is created by default to use it if you want to communicate with other modules that are not related with a specific channel. *
Hydra.module.register( 'moduleId', function( bus )
{
return {
events : {
'channel: {
'item:action1': function ( oData ) {}
}
},
init: function ( oData ) {
$( "#button" ).click( function(){
bus.publish( 'channel', 'item:action1', {} );
});
}
};
});
If you need compatibility with the previous event manager called Action, you can add it in your code to maintain compatibility with previous version's code. You can download it from: [Action](https://github.com/tcorral/Hydra_Extensions/tree/master/Sandbox)
## Documentation
[Project Web](http://tcorral.github.com/Hydra.js)
[API documentation](http://tcorral.github.com/Hydra.js/apis/Hydra.js_API_v2.5.0/index.html)
[Examples](http://tcorral.github.com/Hydra.js/examples/index.html) to see for yourself!
## License
Hydra.js is licensed under the MIT license.
## Agreements
Hydra was inspired by Nicholas Zakas presentation.
* [Scalable Javascript Application](http://www.slideshare.net/nzakas/scalable-javascript-application-architecture)
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "hydra.js",
"filename": "hydra.min.js",
"version": "3.1.1",
"version": "3.1.2",
"description": "Framework that gives you the tools to write your application using modules or widgets and make easy to work with them.",
"homepage": "http://tcorral.github.com/Hydra.js/",
"keywords": [