how can i make a local signal global

kakarlus's Avatar

kakarlus

31 May, 2012 09:02 AM

hi,

i have a signal instantiated and dispatched in my mediator, how can i make it so that the signal can be listened to by other mediators.

thanks,
carlos

  1. 1 Posted by matt on 31 May, 2012 09:36 AM

    matt's Avatar

    create a class that extends Signal and then map this as a singleton in your context - can then inject the signal of this type in your mediators

  2. 2 Posted by kakarlus on 01 Jun, 2012 03:38 AM

    kakarlus's Avatar

    hi matt for the response. my next question is how to pass the argument to the command mapped to the signal.

    thanks,
    carlos

  3. 3 Posted by kakarlus on 01 Jun, 2012 03:55 AM

    kakarlus's Avatar

    i think im having a misconception here, the purpose of the command mapped to the signal is to run the function override which adds listeners to the signal is this correct?
    and in my command i have to inject my model and get the parameters there?

    thanks,
    carlos

  4. 4 Posted by matt on 01 Jun, 2012 09:25 AM

    matt's Avatar

    i think:

    https://github.com/joelhooks/signals-extensions-CommandSignal

    and:

    http://joelhooks.com/2010/02/14/robotlegs-as3-signals-and-the-signalcommandmap-example/

    will do a better job of explaining than i would - when the signal
    dispatches, the command will execute, with the signals parameters injected
    into the command

  5. 5 Posted by kakarlus on 01 Jun, 2012 10:44 AM

    kakarlus's Avatar

    i did what u suggested - put all signals in one class, im getting a stack overflow :s

    my context:
    var appkSignals:AppSignals = new AppSignals(); injector.mapValue(AppSignals, appSignals); signalCommandMap.mapSignal(appSignals.menu_clicked, MenuClickCommand);

    my menu mediator onRegister: // appSignals.menu_clicked is dispatched in menu_clicked
    eventMap.mapListener(view, MouseEvent.CLICK, menu_clicked); appSignals.menu_clicked.add(onMenuClick);

    my MenuClickCommand execute:
    menuModel.expandMenu(menuVO);

    my menu model: (i know this is the one causing the stack overflow) but how am i going to call the mediator listener x_X
    appSignals.menu_clicked.dispatch(menuVO);

    but but if i do this on my context
    injector.mapSingleton(AppSignals);

    the staackoverflow disappears and the MenuClickCommand does not call the method on my menu model

    thanks,
    carlos

  6. 6 Posted by matt on 01 Jun, 2012 12:52 PM

    matt's Avatar

    sorry but i think you misunderstood: the SignalCommandMap works with types
    of Signal that you create that you then map as singletons in your context.
    So instead of AppSignals you would have a class, MenuClicked, which extends
    Signal with an argument of type MenuVO.

    then in your context:

    injector.mapSingleton( MenuClicked );
    signalCommandMap.mapSignal( MenuClicked, MenuClickCommand );

    in your menu mediator:
    [Inject]
    var menuClicked : MenuClicked;

    and when you handle a click from your menu: menuClicked.dispatch( menuVO )

    this will execute your MenuClickCommand, which will have menuVO injected
    into it if required, or you can inject the same signal in the mediators of
    other interested views and handle dispatched directly. You are not calling
    mediator listeners, they are all listening to the same single instance of
    your MenuClicked signal.

    as mentioned in other posts, this approach can end up with a spiralling
    amount of Signal classes that become overwhelming, but it has it's uses.

  7. 7 Posted by neil on 01 Jun, 2012 02:23 PM

    neil's Avatar

    just a slight correction to your example matt:

    the SignalCommandMap has both a

    mapSignal(signal:ISignal, commandClass:Class, oneShot:Boolean = false):void

    and a

    mapSignalClass(signalClass:Class, commandClass:Class, oneShot:Boolean = false):ISignal

    method, you used the mapSignal method but passed the class. :)

  8. 8 Posted by matt on 01 Jun, 2012 04:26 PM

    matt's Avatar

    oops - sorry : | was in a bit of a rush!

  9. 9 Posted by neil on 01 Jun, 2012 04:28 PM

    neil's Avatar
  10. 10 Posted by kakarlus on 05 Jun, 2012 04:26 AM

    kakarlus's Avatar

    tnx for the help guys :)

  11. Ondina D.F. closed this discussion on 21 Jun, 2012 08:04 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