[OpenLayers-Dev] callbacks versus events

Tim Schaub tschaub at opengeo.org
Thu Dec 11 12:25:21 EST 2008


Hey-

bartvde at osgis.nl wrote:
> Hi list,
> 
> can anybody explain to me when to use a callback and when to use an event.
> 
> If I look at the OL codebase, it seems Handlers always use callbacks, and
> controls use events?

When there is potential for multiple listeners, trigger an event.

|
|
  ->
  <-
  ->
  <-
  ...
|
|

When you want to ensure that the the execution sequence branches exactly 
once and returns to your control, use a callback.

|
|
  ->
  <-
|
|

The idea with handlers is that they are supposed to be composed together 
to create specific controls.  When you construct a DragPan control, you 
know what the behavior with respect to dragging will be.  The drag 
handler in this case cannot be used to do anything except what the 
controls intends.

Handlers are somewhat limited in this way.  As enforced by the signature 
of the constructor, they are to be used with a single control.

It would be interesting to talk about how things could be designed 
differently for 3.0 - perhaps having the map trigger things like 
dragstart, drag, dragend, singleclick, etc.  Layers, controls, and other 
things could register listeners for those events and determine behavior 
based on what listeners do and what they return.

Tim

> 
> Best regards,
> Bart
> 
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev


-- 
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.



More information about the Dev mailing list