Hi there,

I strongly feel that the current order of constructor calls for mixins is
wrong.
I didn't want to necropost a thread by Ralf Nieuwenhuijsen[1] that is about 2.5
years old...but it basically explains the reason of this wrong behavior an I
therefore took the liberty and "stole" his description from that thread ;)

Problem/Issue:
==============
> [...]
> The mixin constructor is called _after_ the normal constructor rather than
> before. This is the wrong default.
>
> Why? Because the mixin can make no assumptions about the class it's mixed
> in.. so it won't be calling or setting properties other than its own.
>
> But the class using the mixin knows its using the mixin. It wants to use the
> mixin in the contructor, but it can't.
> [...]


Example:
========
It is not possible to do this:

<code>
qx.Class.define("app.ContextTable",
{
  extend  : qx.ui.table.Table,
  include : qx.ui.table.MTableContextMenu,

  construct : function (tableModel)
  {
    this.base(arguments, tableModel);
    // This *fails*, 'cause the mixins constructor was not yet called!
    this.setContextMenuHandler(0, this.__handler, this);
  },

  members :
  {
    __handler: function (col, row, table, dataModel, contextMenu) {
      return false; // implementation stripped for clarity
    }
  }
});
</code>


I think I will open a bug for this.

In the mean time, does anybody have an idea how to work around this issue with
the current implementation?
My current version (which I don't really like) looks like this:

<code>
qx.Class.define("app.ContextTable",
{
  extend  : qx.ui.table.Table,
  include : qx.ui.table.MTableContextMenu,

  construct : function (tableModel) {
    this.base(arguments, tableModel);
  },

  members :
  {
    /* This method _has_to_be_called_ after instantiating this Table :( */
    initContextMenu : function ()
    {
      this.setContextMenuHandler(0, this.__handler, this);
      return this; // for chaining support
    },

    __handler: function (col, row, table, dataModel, contextMenu) {
      return false; // implementation stripped for clarity
    }
  }
});

// ... somewhere else:
    var tableModel = new qx.ui.table.model.Simple;
    // ...
    var table = new app.ContextTable(tableModel).initContextMenu();
// ...
</code>

Thanks in advance for any hints,
  Peter


[1] http://old.nabble.com/Problems-with-Mixins-td16806052.html#a16806052

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to