<handler>
The receiver in Laszlo's point-to-point event system.

JavaScript: lz.handler

A delegate is an object that calls a specific method on a specific object when its execute method is called. It is essentially a method closure.

Delegates, along with <event>, comprise Laszlo's point to point event system. A delegate represents a named method of an object. Delegates are mostly registered with events, but they can be used anywhere a function callback would traditionally be called for: for instance, LzTimerService.addTimer() takes a delegate as its argument.

You can create a delegate explicitly using the LzDelegate class, or implicitly by specifying an event handler. There are two syntaxes with which you can specify an event handler: in the open tag used to create that object, or by using the <handler> tag in the body of the object.

To specify an event handler in an open tag, simply include it like any other attribute.

 <view onmouseover="doSomething()">
   <method name="doSomething">
     // code to be executed when mouse is over the view
   </method>
 </view>
 

To specify an event hander using the <handler> tag, you include it in the body of the object.

 <view>
  <handler name="onmouseover">
    // code to be executed when the mouse is over the view
  </name>
 </view>
 

The above two examples are functionally equivalent. Using the <handler> tag, however, can often lead to more readable code because it removes clutter from the object creation tag. This is especially true if the handler code is complex.

Note: When creating a delegate explicitly using new LzDelegate, methodName must be a method of one parameter, because it will be invoked by LzDelegate.execute() with one argument (typically the argument that is passed to LzEvent.sendEvent() when that delegate is registered to receive events). Similarly, when specifying an event handler method using <handler ... method="methodName" />, the handler method must accept one argument (even if it ignores it).

See also the code examples at <event> and the Developer's Guide for more detailed information on using events and delegates.

Methods

disable()
handler.disable();
Disables the delegate until enable method is called.

enable()
handler.enable();
Enables a delegate that has been disabled

execute()
handler.execute(eventValue : *);
Executes the named method in the given context with the given data. Returns the result of the call.
Parameter Name Type Description
eventValue * The data with which to call the method.
Returns Type Description
  * The value returned by the method call.

LzDelegate()
handler.LzDelegate(context : lz.Eventable, methodName : String, eventSender : lz.Eventable, eventName : String);
Create an LzDelegate
Parameter Name Type Description
context lz.Eventable The object whose method will be called by execute.
methodName String The name of the method to call (a string). Must be a method of one parameter.
eventSender lz.Eventable (Optional) The sender of the event to register the new delegate for.
eventName String (Optional, but required if eventSender is used) The name of the event to register the new delegate for.

register()
handler.register(eventSender : lz.Eventable, eventName : String);
Registers the delegate for the named event in the given context.

An event is initially declared to contain the sentinel value LzDeclaredEvent which is of the correct type, but does not actually support registering for and sending events. When a delegate attempts to register on this sentinel, the sentinel will automatically be replaced with a functional LzEvent.

The valid event logic is duplicated in NodeModel#addHandlerInternal (to give better location information for handler references).

Parameter Name Type Description
eventSender lz.Eventable The object which publishes the event.
eventName String The name of the event to register for.

unregisterAll()
handler.unregisterAll();
Unregisters the delegate for all of the events it is registered for.

unregisterFrom()
handler.unregisterFrom(event : lz.event);
Unregisters the delegate for the given event
Parameter Name Type Description
event lz.event The event to unregister the delegate from. (e.g. myview.onmouseup)