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

Jonny Reeves's Avatar

Jonny Reeves

Mar 08, 2010 @ 12:50 PM

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 1 Posted by Shaun Smith on Mar 08, 2010 @ 12:55 PM

    Shaun Smith's Avatar

    Have you tried this:

    eventMap.mapListener(myView, ViewEvent.FOO, dispatch, ViewEvent);
    
  2. Support Staff 2 Posted by Till Schneidere... on Mar 08, 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. 3 Posted by Jonny Reeves on Mar 08, 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.

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