LzDelegate

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

A delegate is an object that calls a specific method in a specific context when its execute method is called. It is essentially a function pointer.

Delegates, along with events, comprise Laszlo's point to point event system. A delegate represents a named method of an instance. Delegates are mostly registered with events, but they can be used anywhere a function callback would traditionally be called for: for instance, the LzTimer service takes a delegate as its argument when a timer is started. See the code example on the events page.

Attributes
Name Usage Type (Tag) Type (JS) Default Category
c JS only Object   readonly
  The context in which to call the method

f JS only String   readonly
  The name of the method to call



Methods

constructor()
LzDelegate(context, functionName, eventSender, eventName)
Parameters
Name Type Desc
context Object reference to object which will be called
functionName String name of the method to call (a string)
eventSender Object 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.


disable()
LzDelegate.disable()

Disables the delegate until enable method is called.



enable()
LzDelegate.enable()

Enables a delegate that has been disabled



execute()
LzDelegate.execute(sd)

Executes the named method in the given context with the given data. Returns the result of the call.

Parameters
Name Type Desc
sd The data with which to call the method.
Returns
Type Desc
The value returned by the method call.


register()
LzDelegate.register(eventSender, eventName)

Registers the delegate for the named event in the given context. NB: This is the primary way in which events are created. Published events do not generally exist as objects (with some exceptions) until delegates are created for them.

Parameters
Name Type Desc
eventSender Object The object which publishes the event.
eventName String The name (string) of the event to register for.


unregisterAll()
LzDelegate.unregisterAll()

Unregisters the delegate for all of the events it is registered for.



unregisterFrom()
LzDelegate.unregisterFrom(event)

Unregisters the delegate for the given event

Parameters
Name Type Desc
event LzEvent The event to unregister the delegate from. (e.g. myview.onmouseup)