Convenience Method for Re-dispatching View Events in a Mediator?

Jonny Reeves's Avatar

Jonny Reeves

08 Mar, 2010 12:50 PM via web

This may be more suited for the Google Groups list; but I don't want to add unnecessary noise to that board!

I seems to find writing code to redispatch an event from one of my view components back into the Framework in my Mediators. The code ends up looking like this:

override public function onRegister() : void {
    eventMap.mapListener(myView, ViewEvent.FOO, redispatchEvent, ViewEvent);
}

private function redispatchEvent(event : Event) : void {
    dispatch(event.clone());
}

Is there an opportunity for adding an syntactic sugar to make re-dispatching these View events back into the framework easier, or am I missing something here?

Thanks
jonny.

  1. Support Staff 2 Posted by Shaun Smith on 08 Mar, 2010 12:55 PM

    Shaun Smith's Avatar

    Have you tried this:

    eventMap.mapListener(myView, ViewEvent.FOO, dispatch, ViewEvent);
    
  2. Support Staff 3 Posted by Till Schneidereit on 08 Mar, 2010 12:57 PM

    Till Schneidereit's Avatar

    That functionality is already included - it's just that it's too
    obvious to see. I know that it took a hint in the support area for me
    to see it, at least.

    What you're doing in your redispatchEvent method is exactly what
    dispatch already does for you: It (re-)dispatches an event to the
    Robotlegs event bus. Thus, you can just use dispatch as the event
    handler and be done with it:

    override public function onRegister() : void {
        eventMap.mapListener(myView, ViewEvent.FOO, dispatch, ViewEvent);
    }
    

    In Robotlegs 1.1, that will be simplified to

    override public function onRegister() : void {
        addViewListener(ViewEvent.FOO, dispatch, ViewEvent);
    }
    
  3. 4 Posted by Jonny Reeves on 08 Mar, 2010 12:58 PM

    Jonny Reeves's Avatar

    Well don't I feel foolish! I've just updated the Best Practices document to make mention of this as that's the first place I looked for the answer.

    Thanks guys :)

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