On 2006-03-24 18:14 EST, Jim Grandy wrote:

> [Moved to laszlo-dev]
>
> On Mar 24, 2006, at 9:15 AM, P T Withington wrote:
>
>> I think what you are running up against is a general problem with
>> XML, though.  There are a number of cases in the language where you
>> have an element that has a body and that conflicts with the element
>> wanting to also permit properties.  <text> is another example of this
>> issue.
>
> This has come up in the context of the design of the components, as  
> well: how to allow in-place declaration of combobox options, for  
> example, while still allowing a non-data body for the combobox  
> instance.
>
> One idea I've been kicking around is to introduce an attribute that  
> governs how the body is to be interpreted -- as XML data, or as  
> more LZX. This is a bit weird because it makes the schema dynamic,  
> but would be a clean solution otherwise. So you might have:
>
> <dataset type="direct">
>   <items><item>A</item></items>
> </dataset>
>
> <dataset type="remote">
>   <handler name="ondata">...</handler>
> </dataset>
>
> To avoid the schema problems you could be more verbose and  
> introduce a <data> tag:
>
> <dataset type="direct">
>   <data>
>     <items><item>A</item></items>
>   </data>
> </dataset>
>
> This is one direction I'd like to propose for the components design  
> -- that "direct style" declarations become more verbose so that we  
> can be more data-driven in implementation, and avoid the sort of  
> syntactic limitations discussed in the original message in this  
> thread.
>
> We could then make the syntax less verbose with an XML rewrite  
> engine inserted at the front of the tag compiler. Something using  
> E4X and JavaScript, perhaps... But that's the topic for another time.

This conversation from the archives is relevant.  Oliver's last  
proposed solution 'partial classes' are 'traits'.  I think that is a  
clean solution.  To add attributes to a dataset or dataset instance,  
you put them in a trait and then inherit the trait.  This lets you  
have tags whose body is special, but still extend those tags.

From: Oliver Steele <[EMAIL PROTECTED]>
Date: 1 June 2005 17:01:56 EDT
To: P T Withington <[EMAIL PROTECTED]>
Cc: Antun Karlovac <[EMAIL PROTECTED]>, [email protected]
Subject: [Laszlo-dev] Re: Subclassing dataset

[Added laszlo-dev.]

On May 29, 2005, at 10:37 AM, P T Withington wrote:
 > On 29 May 2005, at 10:01, Oliver Steele wrote:
 >> On May 24, 2005, at 8:01 PM, P T Withington wrote:
 >>> Er, I can see why you can't subclass a dataset instance, because
 >>> you can't distinguish the content from members, but why can't you
 >>> create a subclass of dataset?  Is this because dataset is really
 >>> a special form?  [I'm really asking Oliver this.]
 >>
 >> Right.  Technically, it's because
 >>   <class name="myclass" extends="tag">stuff</class>
 >>   <myclass/>
 >> is defined to be equivalent to:
 >>   <tag>stuff</tag>
 >>
 >> But we could say this isn't true for extends="dataset", and then
 >> you could add methods to a subclass.
 >
 > Oh right.  Adam's nifty thing where you can start with an instance
 > and switch to a class when you need it.

Also here: <http://osteele.com/archives/2004/03/classes-and-
prototypes>.  And it made into into the dguide too, I think.

Text works because it ignores anything that isn't a declared as an
HTML element in the schema.  (Well, that's the spec.  The
implementation is WETter than that.  Now ask me what WET means :-)

 > We have a similar problem with text, right?  Except text happens to
 > work because we can distinguish between plain text (which is
 > treated as content) and tags (which are treated as extensions).
 > That won't work if the content of the text is html will it?  Or are
 > we being even trickier and knowing that only certain tags are
 > extensions?
 >
 > Could we do something like this?
 >
 > <dataset ...>
 >   <?lzx
 >     <attribute ... />
 >     <method ...>
 >       ...
 >     </method>
 >   ?>
 >   <xml>
 >     <content>
 >       <goes here>
 >     </content>
 >   </xml>
 > </dataset>
 >
 > Or instead of <?lzx ... ?> use <![CDATA[ ... ]]>?

I don't like these, since neither one gives <dataset> an <attribute>
element in the source, causing problems for editors and another path
in the compiler.

Some other ideas:

Namespaces
    <dataset name="ds" xmlns:data="local:data">
      <attribute name="a" value="1"/>  <!-- This adds an attribute to
the dataset -->
      <data:attribute name="a" value="1"/> <!-- This is the xml
content of the dataset -->
    </dataset>

I admit I can't quite get this to work, but in case anyone else can
kick life into it...

<Model> element
Require a <model> element for inline data, so anything that isn't
inside the <model> element is property of the instance (or class):

    <dataset name="ds">
      <attribute name="a" value="1"/>  <!-- This adds an attribute to
the dataset -->
      <model>
        <attribute name="a" value="1"/> <!-- This is the xml content
of the dataset -->
      </model>
    </dataset>

This is a breaking change, so it would need to be phased in.  It also
has the disadvantage that not every XML fragment represents an MVC
model.  This is already a source of confusion for server-side
developers.

Subclassing
Fix subclassing dataset, and specify that the class definition can't
have inline data.  (This is the original proposal at the top of this
message.)

    <dataset name="ds">
      <attribute name="a" value="1"/> <!-- This is the xml content of
the dataset -->
    </dataset>

    <class name="mydataset" extends="dataset">
      <attribute name="a" value="1"/>  <!-- This adds an attribute to
the dataset -->
    </dataset>
    <mydataset name="ds">
      <attribute name="a" value="1"/> <!-- This is the xml content of
the dataset -->
    </dataset>

This breaks the instance substitution principle: it's not the same as
subclassing works for other base classes, so it requires special
knowledge on the part of developers and refactoring tools.

Partial classes
I'm going to propose (Real Soon Now) that we add partial classes (aka
open classes), in order to make it possible to reskin components with
the maintenance overhead of copying files, and without the runtime
overhead of subclassing.  This could also be used to add methods to
datasets, if the rule were that inline data is only allowed in the
main class declaration (probably a good rule for independent reasons).

    <dataset name="ds">
      <attribute name="a" value="1"/> <!-- This is the xml content of
the dataset -->
    </dataset>

    <extend name="ds">
      <attribute name="a" value="1"/>  <!-- This adds an attribute to
the dataset -->
    </extend>

(The syntax for partial classes is yet to be decided; this is a stub
so you can see how it would interact with this particular problem.)
_______________________________________________
Laszlo-dev mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-dev

_______________________________________________
Laszlo-dev mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-dev

Reply via email to