Closed gfreeau closed 10 years ago
Done in version 3.4.2
You are a fast worker Tomás!
I have looked at the change and there are some things that could be confusing, on the documentation page: http://tcorral.github.io/Hydra.js/#quickstart there are 4 parameters listed (additional API parameter)
function( Bus, Module, ErrorHandler, Api ){
return {
init: function(){
// Code that will be executed when this module is started.
}
};
}
But in the change there are 3 parameters, bus, module and errorhandler.
I am unsure why hydra.module and hydra.errorhandler needs to get passed to the module. Perhaps you can explain why we would need hydra.module and hydra.errorhandler available to module code?
What I meant by the feature suggestion was just to pass an optional API parameter like this:
function( Bus, Api ){
return {
init: function(){
var element = Api.dom.ById('some-element');
}
};
}
Since accessing the API would be a more common task and avoids referencing the Hydra global every time.
For this to happen, Api would have to be separate singleton like Bus is and then it could be assigned to Hydra.api. Then in extensions, this would be extended instead of the Hydra global.
I think this would make the API a more first class citizen and encourage its use and the final code looks better than many calls to global Hydra.dom, Hydra.ajax etc.
I do not expect you to do this, I am going to work on this for myself, I just wanted to start a discussion. I am still working on familiarizing myself with your code base.
Thanks. I've fixed the documentation and added why I add Bus, Module, ErrorHandler and Api to the constructor as arguments. The most used are Bus, and Module, but ErrorHandler is a big improvement to log messages or errors. If you check Hermes.js you can use it with your Hydra.js modules.
I hope you enjoy with Hydra.js if you need more help let me know. :)
this.api is set in wrapMethod but this method is only called when debug is false (line 707 of Hydra.js).
So when debug is true, this.api does not work in modules as it is undefined.
I think a more simple approach would be to create a new Api singleton like Bus and pass this the module as an optional second parameter. Then instead of extending the Hydra object, the Api object is extended.