[Laszlo-dev] designing API which is LZX friendly and Javascript-friendly

Henry Minsky henry.minsky at gmail.com
Mon Nov 28 08:29:37 PST 2005


Here is a design issue that I am having with the context menu stuff,
which I'd like some developer feedback on.  It is a general issue of
how to build an API that works well for both LZX (XML) style coding,
and also works well for scripting style coding.


PTW suggested something like the following API for LZX for the right click
menu:

<view width="100" height="100" bgcolor="#cccccc" name="v1">
  <contextmenu name="mycmenu" hidebuiltins="true">
    <contextmenuitem name="item1" onselected="parent.parent.showSelectItem
('item1')">
      Item 1
    </contextmenuitem>
    <contextmenuitem name="item2" onselected="parent.parent.showSelectItem
('item2')">
      Item 2
    </contextmenuitem>
  </contextmenu>
</view>


Now, if I implement something like that, there are a number of things
that need to happen automatically when the classes are
instantiated. The "contextmenuitem" needs to place itself into the
parent "contextmenu" instance, and the "contextmenu" needs to install
itself into the parent view.


However, if you are creating and manipulating menus and menu items at
runtime, my feeling is that you do not want these things to happen
automatically for you, you want to have manual control over
instantiating menu items, setting their callbacks, installing them
into menus, and installing the menu itself onto a view.

I have a scripting API that looks like this:

<view width="100" height="100" bgcolor="#cccccc" name="v1">
  <method event="oninit">
    var cm = new LzContextMenu();
    var item1 = cm.makeMenuItem('my item1', new LzDelegate(this,
"handlerightclick1"));
    var item2 = cm.makeMenuItem('my item2', new LzDelegate(this,
"handlerightclick2"));
    cm.addItem(item1);
    cm.addItem(item2);
    this.setContextMenu(cm);
    Debug.write(cm);
  </method>


I don't necessesarily want to have the contextmenu items install
themselves automatically into the parent menu when they are
instantiated; I might want to put them in a different order that the
instantiation order. And I don't necessarily want to install the menu
as soon as I create it, I may want to pre-instantiate the menu object,
but wait until some other event to actually install it on a view.

So the question is, how do you suppress the "automatic" behavior of
the menu item objects when you are instantiating from script. This
seems like a general issue, which must come up in other cases, where
people want to instantiate list menus, comboboxes, etc, at
runtime. Are there a set of guidelines for designing APIs which are
friendly both for LZX and Javascript?





--
Henry Minsky
Software Architect
hminsky at laszlosystems.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://openlaszlo.org/pipermail/laszlo-dev/attachments/20051128/82dd86fc/attachment.html


More information about the Laszlo-dev mailing list