Personal tools

Event and handler tags

From OpenLaszlo

I'd like to propose that we add two new tags to the language: `event` and `handler`

 <event name="eventName" />

This would replace the current idiom of declaring your intention to send an event by using `<attribute name="eventName" value="null" />`. Declaring events means that you can then send them without getting a debugger warning (because the compiler will correctly initialize them). It also gives us freedom in the future of choosing how to implement events.

 <handler name="eventName" [reference="..."] [args="..."]>
   ...
 </handler>

The `handler` tag in this form would be equivalent to the current:

 <method event="eventName" [reference="..."] [args="..."]>
   ...
 </method>

which would be deprecated. This change has two beneficial effects: 1) it simplifies the `method` tag, which would subsequently be used only to define methods, and 2) it permits clearly documenting that handlers are not overridable by subclasses (in meta-object protocol parlance method-combination for handlers is to invoke all methods, not just the most-specific).

The current idiom:

 <method name="methodName" event="eventName" [reference="..."]>
   ...
 </method>

will be replaced by:

 <handler name="eventName" [reference="..."] method="methodName" />
 <method name="methodName">
   ...
 </method>

This change is more complex, but I believe it makes the method tag more understandable, by simplifying it's definition. This is the idiom that would be used to override an event handler, by overriding the method that handles the event.

The `handler` tag in a class definition can be used to define a default handler and to extend the schema to permit specifying the handler body as an opening tag property:

 <class name="className" ...>
   <handler name="eventName" />
   ...
 </class>

permits:

 <className eventName="... javascript ..." />