NodeJS-IRC-Bot icon indicating copy to clipboard operation
NodeJS-IRC-Bot copied to clipboard

evaluate using ComposeJS as a means of supporting inheritance - particularly for plugins

Open ktiedt opened this issue 12 years ago • 7 comments

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)

ktiedt avatar Feb 03 '13 10:02 ktiedt

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.

triplem avatar Feb 03 '13 12:02 triplem

I do not understand your argument about Bracket style.... their patterns are identical except Compose provides a clear means of:

  1. marking a method override as required
  2. 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:

  1. older project, extremely well tested and proven despite its low version num.
  2. 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."

ktiedt avatar Feb 03 '13 16:02 ktiedt

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.

triplem avatar Feb 03 '13 17:02 triplem

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);

ktiedt avatar Feb 03 '13 17:02 ktiedt

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 ;-)

triplem avatar Feb 03 '13 19:02 triplem

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.

triplem avatar Feb 07 '13 17:02 triplem

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...

ktiedt avatar Feb 07 '13 19:02 ktiedt