[OpenLayers-Dev] callbacks versus events

Eric Lemoine eric.c2c at gmail.com
Fri Dec 12 01:37:38 EST 2008


Hi

I just wanted to add that it also makes sense to use callbacks when
composing controls together (within controls). For example having the
modify feature control rely on its select feature control's
featureSelected and featureUnselected callbacks makes sense. Indeed,
in that case the modify feature control is the only one with a
reference to the select feature control, so relying on events here is
not necessary and would come with a greater overhead (more function
calls) than relying on simple callbacks.

Eric

2008/12/11, Tim Schaub <tschaub at opengeo.org>:
> 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.
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>



More information about the Dev mailing list