is addViewListener similar to view.addEventListner ?

vishwas.gagrani's Avatar

vishwas.gagrani

19 Oct, 2012 08:03 PM

Just curious.. if addViewListner() can be replaced view.addEventListener in a project. Or would it cause a breach into the normal flow or way through which Robotlegs functions ?

  1. 1 Posted by Paul Robertson on 19 Oct, 2012 08:28 PM

    Paul Robertson's Avatar

    From a mediator, it's good to use addViewListener() rather than
    view.addEventListener().

    By using addViewListener(), Robotlegs automatically removes the listener
    when the mediator is destroyed, so you're not left with a lingering event
    listener that's keeping things from getting garbage collected. If you don't
    use addViewListener() then you'll want to override the mediator's
    onRemove() method and put a call to view.removeEventListener() in there.

    I don't think this is what you meant, but if you were wondering if you
    should call a mediator's addViewListener() method from another class, I
    would recommend against it, for the same reason it's good to use within the
    mediator. Then the decision of whether your listener is registered or not
    will be linked to whether the mediator exists or not (which generally
    corresponds to whether the view is on the stage or not). Presumably
    something other than the mediator won't want its event listening to be
    controlled by the lifecycle of the mediator.

    Paul

  2. 2 Posted by neil on 19 Oct, 2012 09:05 PM

    neil's Avatar

    just to add to what Paul said is that the same thing is true of addContextListener you could just as well add a listener to the superclass eventDispatcher except that you would have to clean it up on the onRemove hook.

  3. Ondina D.F. closed this discussion on 24 Oct, 2012 07:31 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac