NodeJS-IRC-Bot
NodeJS-IRC-Bot copied to clipboard
evaluate using ComposeJS as a means of supporting inheritance - particularly for plugins
https://github.com/kriszyp/compose
Example irc.js ported to Compose:
https://gist.github.com/4701193
Note: this does not fully demonstrate the benefits of Compose at this point, but this irc.js does appear to be 100% compat with the original irc.js (w/o touching any other code yet)
Hi, there a more modules supporting this kind of OOP stuff. The standard JS way (used in this bot right now) is not as nice. But I just looked at https://github.com/a2labs/riveter - a quite young project - and I do like it. Compose JS looks nice as well, but somehow I dislike the used Bracket style. Makes the code not look as nice.
I do not understand your argument about Bracket style.... their patterns are identical except Compose provides a clear means of:
- marking a method override as required
- AOP functionality... to run an override method before/after the original (or a fancier around() method if needed)
Also it has the added benefits of:
- older project, extremely well tested and proven despite its low version num.
- it's not a "trial" that may go away:
"riveter is currently an 'appendTo Labs' effort. This means that we're excited about it enough to make it a micro-library - and we invite you to try it out with us and give us your feedback. However, being that it's experimental, we may also decide it's the worst idea since the 8-track cassette player. As long as it continues to prove promising, it stands the chance of becoming a more 'officially supported' appendTo project. In short - we may pull the plug or change the name at any moment."
You are right about the two last points, riveter seems to be a little too "cutting edge".
Basically both seem to provide the same kind of functionality, but IMHO it is cleaner to say
var Employee = function( name, title, salary ) {
Employee.__super.call( this, name );
this.title = title;
this.salary = salary;
};
riveter.inherits( Employee, Person );
then the compose style:
HelloWidget = Compose(Widget, {
message: "Hello, World",
render: function(){
this.node.innerHTML = "
" + this.message + "
";
}
});
var widget = new HelloWidget();
widget.render(node);
Probably I am mistaken. For me there are too much brackets in there.
What the equivalent example would be:
var Employee = Compose(function(name, title, salary) {
// not seeing a good example for the super call in this case but
this.title = tile,
this.salary = salary;
};
Employee.extend(Person);
Ah, I see, it is pretty much the same. First impression was that I do need more brackets and that I need to put everything in this Compose(-Bracket stuff. Anyway, me is not really a JS expert. So, I guess, the Plugins should definitly adopt this, since then we could use clean inheritance for those ;-)
I have now found a quite easy solution, without the necessity to load another component. We could basically just use util.inherits and everything is fine. See my branch "inheritance" and the plugins/BasePluginStandard.js and plugins/freenode.js.
All tests run fine ;-) I am going to use this one in the future and remove the pluginHelper.js again, which right now encapsulates some fundamental functionality for all plugins.
This is fine for very basic functionality, but I still see Compose.before/after/around being very useful methods for Plugin writing -- which util.inherits can achieve, but not in a convenient way...