Q to understand Signals BP

havarez's Avatar


08 Nov, 2010 10:11 AM

Hi all!

I want to understand if I am using signals right (Best Practices).

I have RenderGraphics component in my view components.
It has -- public var frame :Signal = new Signal;
and dispatches it every frame -- frame.dispatch(posX, posY);

In my RenderGraphicsMediator I have:
[Inject] public var enterFrameSignal :EnterFrameSignal; that is mapped as singleton in context -- injector.mapSingleton(EnterFrameSignal);

What I am doing is when "frame" signal comes from view component I am transmitting it to framework:
private function frameUpdated(posX:int, posY:int):void

   enterFrameSignal.dispatch(posX, posY);


So, RenderGraphics has a good incapsulation (dont depends on EnterFrameSignal class). But I have many signals that I want just to transmit to framework (no additional logic in Mediator) - and for every one I need to create custom Signal class an code in mediator.

Maybe there is any way just to transmit signal from component to framework? (which not ruins BP approach)

  1. 1 Posted by Stray on 08 Nov, 2010 10:51 AM

    Stray's Avatar

    Hi there,

    others may have more thoughts, but here are a few:

    For enter-frame, a centralised signal (one for the whole app) is a nice approach that cuts down on overhead - Robert Penner has done some benchmarking that shows that it's an efficient approach compared with listening for enter-frame in multiple places. (You might only be doing it in one place anyway). But in this incidence your EnterFrameSignal seems to carry x and y coordinates, so it might not be relevant to centralise it.

    You would have the mediator receive the EnterFrameSignal and expose an API on the view to get x and y ... but that seems like it wouldn't fit with what you need.

    Another option is to use the mediator to set the signal on the view.

    same as you are currently doing in the mediator:

    [Inject] public var enterFrameSignal :EnterFrameSignal;

    but then also

    view.frame = enterFrameSignal;

    and in view:

    public function set frame(frameSignal:Signal):void
    _frame = frame;

    Then you just dispatch as normal in your view, but you'd miss out the stage in the mediator where you re-transmit it.

    You could even inject the signal into your view, but things can get tangled fast with view-injection.

    Personally I'd probably stay with the more verbose implementation because I think it's possible to see the two signals as being different things that currently happen to be well aligned, but this approach above would be very easy to refactor to the original implementation you have below so I think it's a pretty good compromise.

  2. 2 Posted by Stray on 08 Nov, 2010 11:43 AM

    Stray's Avatar

    Of course I meant that you could even 'auto-inject' the signal to the view. What I described is setter injection - you're still injecting the dependency, just through a function rather than the [Inject] auto-magic route.

  3. 3 Posted by havarez on 09 Nov, 2010 03:14 PM

    havarez's Avatar

    Thank you!

  4. Stray closed this discussion on 10 Feb, 2011 06:08 PM.

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

Keyboard shortcuts


? 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